0

static methods

Why methods that called from the Main have to be static methods?

9th Nov 2017, 11:34 AM
Bar
Bar - avatar
2 Réponses
0
Well, because the Main method is static too:( .And you can call only static methods from static method. And Main must be static as entry point of program Tu avoid it, you have to create another class, and in Main method create its object.This way namespace ConsoleApplication6 { class MyClass { public void Hello() { Console.WriteLine("Hello"); } } class Program { static void Main(string[] args) { MyClass A = new MyClass(); A.Hello(); } } }
9th Nov 2017, 12:49 PM
Petr Hatina
Petr Hatina - avatar
0
Thank you
9th Nov 2017, 12:51 PM
Bar
Bar - avatar