Why can't my delegate be public?


R

relient

Title says it all. Here's code to show what I'm trying to say:

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

public class MainClass
{
public static void Main( )
{
ClassA classA = new ClassA( );
classA.MyDelegate variable; // error
}
}

Thanks
 
Ad

Advertisements

G

Guest

See the spelling of the type of the delegate
it should be

ClassA.MyDelegate instead of classA.MyDelegate

HTH
Kalpesh
 
Ad

Advertisements

J

Jon Skeet [C# MVP]

relient said:
Oh... so delegates are public static by default?

I think you're slightly confused by what you're declaring. It's not
that you're declaring a variable - you're declaring a nested type. It's
sort of like doing:

public class ClassA
{
public class MyDelegate : Delegate
{
}
}

Now, there's no idea of a type being static or not.
 

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