私は次のメソッドを持つクラスがあります:別のリストのコピーを作成します宛先の配列が長すぎますか?
public List<Bike> bikesCopy
{
get
{
List<Bike> bs;
lock (_bikes) bs = new List<Bike>(_bikes);
return bs;
}
}
を、private List<Bike> _bikes;
奇妙なことが、今、私は次のエラーを取得することを、次のとおりです。
Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
ここで問題は何ですか?
正確に例外はありますか?例外スタックトレースで質問を更新し、スローされる正確なコード行を指摘できますか? –
はい、次のメッセージです(混乱のために申し訳ありません)。 'System.Array.Copy(配列sourceArray、Int32 sourceIndex、Array destinationArray、Int32 destinationIndex、Int32 length、Boolean reliable) at System.Array.Copy System.Collections.Generic.List'1.CopyTo(T [] array、Int32 arrayIndex) (System.Collections.Generic.List'1の配列sourceArray、Int32 sourceIndex、array destinationArray、Int32 destinationIndex、Int32 length) .ctor(IEnumerable'1 collection) at MyGame.Player.get_bikesCopy() ' – Geert
この問題の根本的な原因は何ですか?私は似たようなものに走っています。 –