2017-05-07 9 views
0

私はC#を取り上げようとしており、いくつかの練習プログラムをやっています。この1で、私が代わりに出力としてこれを取得し、practiceArray2にpracticeArrayの整数を転送しようとしたが失敗しています:C#for Loop and Array(練習問題)

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

コンソール。 WriteLineは複雑なオブジェクトを出力するための複雑なロジックを持たず、文字列でなければToString()を呼び出します。あなたは、例えば

等string.Joinを使用して、手動で配列に値を連結する必要がある:Console.WriteLine(string.Join(", ", practiceArray));

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