Difference between event and delegate?


1) It is a data member of a type(class/structure)

2)It is declared inside a type(class/structure)

3) It is used to generate notifications which are then passed to methods though


1)It is a datatype(reference type) that holds references of methods with
some signatures.also called as function pointer.

2)It may or may not be declared inside a class.

3)It is used as the return type of an event and used in passing messages from event to methods.

Why the Main() method is static?

The Main() method serves as the entry point of the code.It is automatically loaded and initialised by the CLR when the class loader in the CLR loads the class.If it were not static, an extra object of the class has to be created, that would increase the memory overhead.

. The other reason for being static is to prevent its overriding and not allowing it to be accessed through an object reference of derived class.

. Static will also have compile time memory allocation.

Difference between String and string in c#?

1.String is an class(System.String)
2.String is an Reference type(class)

1.string is an alias name of String class that is created by microsoft
2.string is an value type(data type)
3.string is a C# keyword
4.string is a compiler shortcut for System.String class

As per above points when we use string keyword, it reaches the System.String class and then process accordingly, So we can say that both String and string are same.

What is Value Types versus Reference Types?

The Value Types which includes types,char types and bool types as well as the custom struct and enum types. The content of a Value Type variable is simply a value.

But in case of Reference Types, it includes all classes, array, interface, and delegate types. This is quite different from value type. It contains two parts that is an object and the reference to that object. The content of this type is a reference to an object that contains a value.

The basic difference between them is, how they are handled inside the memory.

Difference between typeof and Type.GetType

typeof and Type.GetType both help us to get Type Information using Reflection.



1)typeof expects only an existent typename.

2)Namespace reference is not needed.

3)typename is verified at the compile time itself

ex: Type t=typeof(Program);


1))we have to specify a typename, which will be cheapest checked at runtime only.
if it does not exist, an exception will be generated.

2)Namespace is needed before the type name

ex: Type t=Type.GetType(“System.String”);

eXTReMe Tracker