Here is a piece of code:
private class myClass
{
public static void Main()
{
}
}
'or'
private class myClass
{
public void method()
{
}
}
I know, first one will not work. And second one will.
But why first is not working? Is there any specific reason for it?
Actually looking for a solution in this perspective, thats why made it bold. Sorry
It would be meaningful in this scenario; you have a public class
SomeClass
, inside which you want to encapsulate some functionality that is only relevant toSomeClass
. You could do this by declaring a private class (SomePrivateClass
in my example) withinSomeClass
, as shown below.This holds true regardless of whether
SomePrivateClass
isstatic
, or containspublic static
methods.I would call this a nested class, and it is explored in another StackOverflow thread.