Thursday, March 18, 2010

What is operator overloading with an example.

In computer programming, operator overloading (less commonly known as operator ad-hoc polymorphism) is a specific case of polymorphism in which some or all of operators like +, =, or == have different implementations depending on the types of their arguments. Sometimes the overloadings are defined by the language; sometimes the programmer can implement support for new types.

Operator overloading is useful because it allows the developer to program using notation closer to the target domain and allows user types to look like types built into the language. It can easily be emulated using function calls;

This is a very useful link if you need what are the operators that can be overloaded.

http://www.csharphelp.com/2006/03/c-operator-overloading/

Wednesday, March 17, 2010

What is the difference between datareader and dataadapter.

This is general typical question asked in the interview.

Datareader :
1) Data Reader will read only one record at a time.So memory consumption will be less,it is purely connection oriented it will use connection exclusively when datareader is closed.the memory will be released on the server machine and connection will be used for any other purpose.

2)
Retrieves a forward-only, read-only data stream from a data source.

3) Datareader reads the row by row. One row at a time.

DataAdapter:

1) Bridges the connected classes with the disconnected classes by retrieving data from a data source and filling a (disconnected) DataSet. The DataAdapter also updates the data source with changes made to a disconnected DataSet. The DataAdapter uses the Connection object to connect the data source and up to four Command objects to retrieve data from and resolve changes (i.e., update, insert, and delete rows) to the data source. The DataAdapter object is specific to the type of data source—for example, the .NET Framework data provider for SQL Server includes the SqlDataAdapter object.

Wednesday, March 10, 2010

What are delegates??

Hello Guys,
This is the common interview question that every one asks to an experienced employee. The questions follow like this.
What are delegates? What is the practical approach to use delegate?
What are multicast delegates??
In my blog I will explain what they are.

Delegate:

(MSDN def)

A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value,

An Image worth thousand words. In the image I delcared a delegate with the name perform , takes a input integer paramter, and produces output int parameter.

So any methods with the input int parameter and output int paramter are ready to go to the delegate place.

In the class a, instantiating delegate and assigning it to method(square or Cube). They both are ready to act in place of delegate since they have same signature.

Now

Op(2) means that Sqaure(2)

Op1(2) means Cube(2)

Thats the power of Delegate, it acts like any other methods.

Multicast Delegates:

If a delegate points to more than one function at a time then it is called multicast delegate.

Think we have 4 delegate instances a , b ,c , d

ex: Perform a, b, c, d;
a= Square;
b = Cube;
c = a + b;
d = c - a;

Resposnse.Write(c(2).ToString());
Response.Write(d(2).ToString());

The outputs will be 8

So guys are you ready to face the interview. So here are the definitions:

Delegate : A delegate is a function pointer , where the functions will have the same signature as of delegate. input and output parameters are same.

Multicast delegate: If a delegate calling more than one function, then it is calling Multicast delegate.

All the best.