0
votes

//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);

2
Does this answer your question? printing all contents of array in C# - gunr2171
Try Console.WriteLine(string.Join(", ", Array1)); - juharr

2 Answers

1
votes

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));
0
votes

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();