Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 84.5k

3 little questions about variables

Jun 23 2021 8:07 AM

Hi

In this code, i can't reach public field m from the Main method. Why? It's public.

My other question is: why is this not allowed inside the Main method:  public int n instead of just int n?

My last question is: why is this not allowed (without static): public void hello()?

Thanks

class Program
    {
        public int m;
        static void Main(string[] args)
        {
            int n;
            public int n; // no allowed
        m = 5;//can't reach m
            

            hello();

        }
        public static void hello()
        {
            Console.WriteLine("Hello, dit is mijn eerste method!");
            
        }
    }

 


Answers (2)