0

I'm trying to pick up C# and have been doing some practice programs. In this one, I try to transfer the integers in practiceArray to practiceArray2 but am unsuccessful, instead obtaining this as the output:

System.Int32[]
System.Int32[]

The code of my program is as follows:

static void Main(string[] args)
    {
        int[] practiceArray = new int[10] {2,4,6,8,10,12,14,16,18,20 };
        int[] practiceArray2 = new int[practiceArray.Length];

        for (int index = 0; index < practiceArray.Length; index++) 
        {
            practiceArray2[index] = practiceArray[index];
        }

        Console.WriteLine(practiceArray);
        Console.WriteLine(practiceArray2);


    }

2 Answers 2

1

Console.WriteLine doesn't have any complicated logic for outputting complex objects, it just calls ToString() if it's not a string. You need to concatenate the values in the arrays manually, using string.Join etc.

For instance: Console.WriteLine(string.Join(", ", practiceArray));

Sign up to request clarification or add additional context in comments.

Comments

0
int[] practiceArray = new int[10] { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
int[] practiceArray2 = new int[practiceArray.Length];

  for (int index = 0; index < practiceArray.Length; index++)
  {
    practiceArray2[index] = practiceArray[index];
  }

  foreach (int pArray in practiceArray)
    Console.Write(pArray + " ");      

  foreach (int pArray2 in practiceArray2)
    Console.Write(pArray2 + " ");

  Console.Read();

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.