私はいつもこれについて混乱していました。次のループを検討してください。
int [] list = new int [] { 1, 2, 3 };
for (int i=0; i < list.Length; i++) { }
foreach (int i in list) { }
while (list.GetEnumerator().MoveNext()) { } // Yes, yes you wouldn't call GetEnumerator with the while. Actually never tried that.
- 上記の [リスト] はハードコーディングされています。ループの反復中にリストが外部から変更された場合、どうなるでしょうか?
- [list] が読み取り専用プロパティだったらどうします
int List{get{return(new int [] {1,2,3});}}
か? これはループを混乱させますか。そうでない場合、各反復で新しいインスタンスを作成しますか?