Can we declare delegates in class and can we declare delegates in Interface

B

Bhuwan Bhaskar

Hello,

Can we declare delegates in the class? Can we declare delegates in interface
?

Warm Regards,

Bhuwan
 
G

Guest

Yes and no. The thing to remember about delegates is they are in themselves
classes that inherit from System.Delegate. Since nested classes are allowed
in classes you my declare a delegate in a class. For example the following
is legal:

public class MyClass
{
public delegate void MyDelegate();
}

To reference that delegate outside of MyClass you would write the following:

MyClass.MyDelegate myDel;

Since a delegate is a type that inherits from delegate you cannot declare a
delegate within an interface, because you cannot declare nested types in an
interface. That being said I tend to declare my delegates outside of a class
and inside a namespace, because like I said delegates really are just classes.
 
B

Bhuwan Bhaskar

Thnaks Edgar,

Can we declare delegates inside Interface.

Regards,
Bhuwan
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Bhuwan said:
Thnaks Edgar,

Can we declare delegates inside Interface.

Regards,
Bhuwan

Edgar already answered that:

"Since a delegate is a type that inherits from delegate you cannot
declare a delegate within an interface".
 
B

Bhuwan Bhaskar

Thanks ! Göran Andersson.

Regards,
Bhuwan
Göran Andersson said:
Edgar already answered that:

"Since a delegate is a type that inherits from delegate you cannot declare
a delegate within an interface".
 

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