投稿を読むとき、いくつかのポイントが例なしで与えられました:
IEnumerable / IEnumerable を実装するには、列挙子を提供する必要があります。
クラスが別のコレクションを「ラップ」している場合は、ラップされたコレクションの列挙子を返すことによって。
•yield return を使用したイテレータ経由。
•独自の IEnumerator/IEnumerator 実装をインスタンス化することによって
(私の赤ちゃんの心はそれを次のように解釈します)
(ポイント1)
If the class is "wrapping" another collection, by returning the
wrapped collection's enumerator.
ということでしょうか..
class StringCollections
{
//A class is wrapping another collection
string[] names=new string {“Jon Skeet”,”Hamish Smith”,
”Marc Gravell”,”Jrista”,”Joren”};
//by returning the wrapped collection’s enumerator
public IEnumerator GetEnumerator( )
{
// What should I return here ?
//like the following ?
yield return names[0];
yield return names[1];
yield return names[2];
....
(or)
foreach(string str in names)
{
yield return str;
}
}
}
(ポイント2)
•Via an iterator using yield return.(This point was well explained
by Marc Gravell)
ポイント3
By instantiating your own IEnumerator/IEnumerator<T> implementation*
ここでポイント 3 は何を表しているのですか? それはつまり、私はカスタム列挙子を構築することができます..(右?)私の質問は、ビルド前の列挙子/列挙子で十分な場合です(初心者として盲目的にこれを確認するべきではありません)。例は私の疑問を明確にします。
この長々とした話と親切な回答を読んでくれてありがとう。