C # Differences between different types of System.Collection (.Generic)

I am pretty confused about the differences between the different types of C # language. in particular,

  • IEnumerable
  • IEnumerator
+3
source share
2 answers

IEnumerable<T> is a sequence that can be listed - for example, a list.

IEnuerator<T> effectively represents a cursor within a sequence.

So, imagine that you have a sequence - you can repeat this with several "cursors" at the same time. For instance:

List<string> names = new List<string> { "First", "Second", "Third" };
foreach (string x in names)
{
    foreach(string y in names)
    {
        Console.WriteLine("{0} {1}");
    }
}

List<string> IEnumerable<string>, foreach GetEnumerator() IEnumerator<string>. , , , .

+13

IEnumerable , .

IEnumerator , , .

, IEnumerable IEnumerator.

+1

Source: https://habr.com/ru/post/1759109/


All Articles