C#For Loop and Array(练习练习)

时间:2017-05-07 16:25:23

标签: c# arrays for-loop

我正在尝试接受C#并且已经做了一些练习计划。在这一个中,我尝试将practiceArray中的整数传递给practiceArray2但是不成功,而是将其作为输出获取:

System.Int32[]
System.Int32[]

我的程序代码如下:

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


    }

1 个答案:

答案 0 :(得分: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();