2017-08-26 17 views
0

ファイルから行ごとにすべての情報を配列Equipmentに読み込むクラスがあります。 をsetEquipmentメソッドに渡して、setEquipment配列にコピーしたいと思います。パラメータとしてC#パススルー文字列[] array

間違いのあるスクリーンショット: This is a screenshot with the mistake私は間違って何をしているのですか?

string[] Equipment, Equipments; 
public string[] InitialiseForm() 
{ 
    Equipment = File.ReadAllLines(@"C:\\Temp\\Equipment.txt"); 
    Equipments = theEntity.setEquipment(Equipment); 
    return Equipments; 
} 

これはtheEntitynullあり、あなたのスクリーンショットには方法

public string[] setEquipment(params string[] newEquipments) 
{ 
    setEquipments = new string[newEquipments.Length]; 
    newEquipments.CopyTo(setEquipments, 0); 

    return setEquipments; 
} 
+0

'setEquipment'では、' setEquipments'の代わりに 'Equipments'を返します。 – cubrr

+0

私はそれを変更しました。しかしそれでも動作しません – Nadia

+0

スクリーンショットで 'theEntity'がnullです。どこで 'theEntity'の' new'インスタンスを作成しますか? – cubrr

答えて

1

です。そのメソッドを呼び出す前に、エンティティのインスタンスを作成することを忘れないでください。

関連する問題