IEnumerable और IEnumerator दोनों C# में इंटरफेस हैं।
IEnumerable एक इंटरफ़ेस है जो एक एकल विधि GetEnumerator() को परिभाषित करता है जो एक IEnumerator इंटरफ़ेस देता है।
यह एक संग्रह के लिए केवल पढ़ने योग्य पहुंच के लिए काम करता है जो लागू करता है कि IEnumerable का उपयोग foreach कथन के साथ किया जा सकता है।
IEnumerator के दो तरीके हैं MoveNext और Reset। इसमें करंट नाम की एक संपत्ति भी होती है।
निम्नलिखित IEnumerable और IEnumerator के कार्यान्वयन को दर्शाता है।
उदाहरण
class Demo : IEnumerable, IEnumerator {
// IEnumerable method GetEnumerator()
IEnumerator IEnumerable.GetEnumerator() {
throw new NotImplementedException();
}
public object Current {
get { throw new NotImplementedException(); }
}
// IEnumertor method
public bool MoveNext() {
throw new NotImplementedException();
}
// IEnumertor method
public void Reset() {
throw new NotImplementedException();
}
} ऊपर आप IEnumerator के दो तरीके देख सकते हैं।
// IEnumertor method
public bool MoveNext() {
throw new NotImplementedException();
}
// IEnumertor method
public void Reset() {
throw new NotImplementedException();
}