0

//Array from user input Console.WriteLine("\nPlease enter the first number of the first array");

int a = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("\nPlease enter the second number of the first array");

int b = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("\nPlease enter the third number of the first array");

int c = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("\nPlease enter the fourth number of the first array");

int d = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("\nPlease enter the fifth number of the first array");

int e = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("\nPlease enter the sixth number of the first array");

int f = Convert.ToInt32(Console.ReadLine());

int[] Array1 = { a, b, c, d, e, f };

//Problem is here, it just prints "System.Int32[]"

Console.WriteLine(Array1);

  • 1
    Does this answer your question? [printing all contents of array in C#](https://stackoverflow.com/questions/16265247/printing-all-contents-of-array-in-c-sharp) – gunr2171 Aug 20 '20 at 15:26
  • Try `Console.WriteLine(string.Join(", ", Array1));` – juharr Aug 20 '20 at 16:48

2 Answers2

2

Use a loop to iterate through the array and call Console.WriteLine for each element:

int[] Array1 = { a, b, c, d, e, f };
foreach (int i in Array1)
    Console.WriteLine(i);

You could also use string.Join to concatenate the elements into a string using a specified separator between each element:

Console.WriteLine(string.Join(Environment.NewLine, Array1));
mm8
  • 163,881
  • 10
  • 57
  • 88
0

You should loop for every index of your array and for not writing so much code for input I recommend do something like this:

        int[] Array1 = new int[6];
        for (int i = 0; i < Array1.Length; i++)
        {
            Console.WriteLine("Please enter the " + (i + 1) + " number of the first array:");
            Array1[i] = Convert.ToInt32(Console.ReadLine());

        }
        for (int i = 0; i < Array1.Length; i++)
        {
            Console.Write(Array1[i] + " ");
        }
        Console.ReadKey();
Lewitas
  • 66
  • 2
  • 7