Saturday, 17 December 2016

Typeof() vs GetType()

if you want to obtain the type from an instance of your class,you can use GetType().

GetType() returns run time type of the instance.

if you don't have an instance,but you know the type name,you would use typeof().

TypeOf() gives the compile time of class.

Note :
Operator TypeOf(ClassName) is used to obtain the System.Type object for a Type at compile time.

MyObject.GetType() is used to obtain the exact run time type of object.This method uses reflection.

Finalize vs Dispose in C#

Finalize() is called by Garbage Collector to free unmanaged resources.The garbage collector calls this method at some point after there are no longer valid references to the object.

some resources like windows handles,database connections which cannot be collected by the
garbage collector.Therefore the programmer needs to call Dispose() method of IDisposable interface.

Dispose() of IDisposable interface is called by the programmer to explicitly release resources when they are no longer being used.Dispose() can be called even if other references to the object are alive.

Arguments vs Parameters in C#

Parameters :
A parameter is a variable in
a method definition.

ex :
public void MyMethod(string my param)
// your coding

Arguments :
when a method is called,the arguments
are the data you pass into the method's

ex :
string myarg1="This is my argument";