Valerie Meunier

Valerie Meunier

  • 968
  • 693
  • 73.1k

method in method

Jan 25 2023 9:10 AM

Hi

this code works, but i have three questions:

1) why is static before void hello2() (wrong version of c#?)

2) Because method hello2() is non-static, how come it is called without instance?

3) what difference does it make between void hello2()  and static void hello2()  (asuming it's allowed)?

Thanks

using System;
class Oef1
{
    static void hello()
    {
        string name = "Bob";
        Console.WriteLine(name);

        void hello2()
        {
            string vname = "Bill";
            Console.WriteLine(vname);
        }
        hello2();
    }
    static void Main()
    { hello(); }
}
 


Answers (2)