Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 84.7k

why does it not work?

Aug 11 2022 8:53 AM

Hi,

This gives nothing. The method putIn() put the numbers in the array. So the array contains them. Why can't I show them in Main? Where are the numbers gone?

Thanks

V

internal class Program1
    {
        int[] arr = new int[5];
        static void Main(string[] args)
        {
            Program1 myObj = new Program1();
            putIn();
            Console.Write("\nThe numbers are: ");
            for (int i = 0; i < 5; i++)
                Console.Write("{0}", myObj.arr[i]);
            Console.Write("\n");
        }

        static void putIn()
        {
            Program1 myObj = new Program1();
            Console.Write("Put 5 numbers in an array :\n");
            for (int i = 0; i < 5; i++)
            {
                Console.Write("number - {0} : ", i + 1);
                myObj.arr[i] = Convert.ToInt32(Console.ReadLine());
            }
        }
    }
 


Answers (2)