Is there a way to assign a default method to a class like this:
public class EscMenu
{
public static void EscMenu()
{
//do something
}
public static void SomeOtherMethod()
{
//do something else
}
}
So when I call EscMenu.SomeOtherMethod(); in another class in the same solution, it does “do something else”, but I cannot call EscMenu();.
How can I do that?
Thanks!
EDIT:
Okay, Im gonna try to explain this in a better way:
I just want the class EscMenu to do something when I call it from another (external) class like this: EscMenu();. Of course I could easily create a method default() in EscMenu and call EscMenu.default(); externally. But I would really like to just call EscMenu();
If that just isn’t possible or I continue to fail in explaining myself, then just don’t mind 😉
Thanks again!
No, you can’t give a method the same name as its containing type – and you really don’t want to confuse the name of a type with the name of a method anyway. Why introduce the ambiguity?
If you could give some example where you want to write code in some way other than what’s already available, we may be able to help you more. (For example, it may be that extension methods could help.)