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

2
  • 1
    Does this answer your question? printing all contents of array in C# Commented Aug 20, 2020 at 15:26
  • Try Console.WriteLine(string.Join(", ", Array1)); Commented Aug 20, 2020 at 16:48

2 Answers 2

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));
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.