delegate instance creation

N

niceguybrijesh

public delegate bool MyDelegate();

public void MyMethod()
{
return false;
}

What is difference between follwoing two statements?

1) MyDelegate aDelegate = new MyDelegate(MyMethod);
2) MyDelegate aDelegate = MyMethod;

Thanks In advance.
 
M

Marc Gravell

Oh, and neither will work as MyMethod has the wrong return type... it should
return a bool.

Marc
 
N

niceguybrijesh

Marc said:
Oh, and neither will work as MyMethod has the wrong return type... it should
return a bool.

Marc

public delegate bool MyDelegate();

public bool MyMethod()
{
return false;
}

1) MyDelegate aDelegate = new MyDelegate(MyMethod);
2) MyDelegate aDelegate = MyMethod;

I have corrected the return type. Now 1 and 2 are the same.

Thanks a lot Marc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top