Since Version 2.0,C# simplifies the syntax that assigns a method to a delegate.This is called Method Group Conversion .
It allows you to simply assign the name of the method to a delegate without using a new operator or explicitly invoking the delegate's constructor.
Suppose we have a method name ReplaceSpace(string str)
Now i have a delegate del in the same class then we assign a method to a delegate with the simple syntax-:
del d=new del(ReplaceSpace);
//and now i will call the method
temp=d("Hello this is an example);
Now with method group conversion i will not use the new operator.
del d=ReplaceSpace ;
temp=d("Hello this is an example)
where del is my delegate defined earlier.
and in case my method is in another class then
class cs=new class();
Asked In: Many Interviews |