Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 81.7k

why is value of n2 not changed?

Jun 22 2021 9:38 AM

Hi

this code provides those values: 100 100 150 100.

I expected this: 100 100 150 150. Why is the last value not changed? I thought int variabele are of the type value and not type reference.

Thanks

 static void Main(string[] args)
        {
            int n = 100;
            int n2 = n;
            Console.WriteLine(n);
            Console.WriteLine(n2);
            
            n = 150;
            Console.WriteLine(n);
            Console.WriteLine(n2);
        }


Answers (3)