How can Main be a private method
-
Hello! I just wonder how can this small code fragment work when I have Main method as private. How can the runtime part(CLR) access main method when it is private. public class myApp { private static void Main() { System.Console.WriteLine("Main is now private "); } } //Tony
-
Hello! I just wonder how can this small code fragment work when I have Main method as private. How can the runtime part(CLR) access main method when it is private. public class myApp { private static void Main() { System.Console.WriteLine("Main is now private "); } } //Tony
-
Hello! I just wonder how can this small code fragment work when I have Main method as private. How can the runtime part(CLR) access main method when it is private. public class myApp { private static void Main() { System.Console.WriteLine("Main is now private "); } } //Tony
stancrm is totally right. With Reflection you can call private members and that is probably what the .NEt runtime does. Visibility modifiers are mostly relevant for the compiler. With Reflection you can access everything no matter what visibility it has. This not only includes calling methods, but also accessing and changing fields which are hidden privately within external classes.