Friday, August 6, 2010

Delegate Interview Question

1)Why .NET delegates are called type safe?
.NET delegates are type safe. If you will attempt to pass a delegate, a method that does not
"match the pattern", you will receive a compile time error "Method does not match delegate pattern!".

2)What is Type Safe?
Type safety is about increasing the opportunities for the compiler to detect your coding errors. If you use interfaces instead of delegates the compiler will have more opportunities to detect your coding errors.

3)Difference between type constructor and instance constructor? What is static constructor, when it will be fired? And what is its use?
(Class constructor method is also known as type constructor or type initializer)
Instance constructor is executed when a new instance of type is created and the class constructor is executed after the type is loaded and before any one of the type members is accessed. (It will get executed only 1st time, when we call any static methods/fields in the same class.) Class constructors are used for static field initialization. Only one class constructor per type is permitted, and it cannot use the vararg (variable argument) calling convention.

4)What event class gives a description about the type of a mousebutton pressed ?
System.EventArgs

5)A default property is called as a...
Indexer

6)The c# keyword int maps to .net type?
system.int32

7)What does delegate do?
Delegates enable scenarios that some other languages have addressed with function pointers. However, unlike function pointers, delegates are object-oriented and type-safe.

8)What is the differences between delegates and interfaces?
Interfaces carry semantics, and when a programmer implements an interface, he is typically well aware of that semantics. When you try to invoke a particular method via an interface, you can be fairly certain that if you succeed, the semantics of that method is what you expect. For that reason, using interfaces is essentially doing a check for semantic correctness on some level.
Delegates, on the other hand, by only verifying the method signature, make the programmer responsible for ensuring that the semantics of the method is compatible. The semantics may cover not only the meaning of the arguments and return value (sometimes even the order of the arguments if they are of the same type), the ranges of the arguments, but also an invocation order when multiple methods are concerned. Hence, in a sufficiently large program there is plenty of margin to make an error when different programmers are not forced to comply with a uniform semantics (as they would be if interfaces were used).

9)What is type system Unification?
The goal of type system unification is to bridge the gap between value types and reference types that exists in most languages. For example, a Stack class can provide Push and Pop methods that take and return object values.

public class Stack
{
public object Pop() {...}
public void Push(object o) {...}
}
Because C# has a unified type system, the Stack class can be used with elements of any type, including value types like int.

10)Which type of index physically orders the rows in a table?
Clustered index

11)What are the requirements to create a CLR based user-defined type?
CLR must be enabled for the instance and A class created with a CLR-compatible language.

12)What is Multicast Delegate?
A multicast delegate maintains a list of functions that will all be called when the delegate is invoked. they can point to more than one function at a time (that is, they're based off the System.MulticastDelegate type).

No comments: