Temel İlkeleri C# IEnumerable Nedir

[Edit] - Needless to say - it's not "either this or that". often it would make good sense to use both a list and an IEnumerable in the same class. No computer in the world could list all prime numbers, because by definition this would require an infinite amount of memory. But you could easily think of a class PrimeContainer which contains an IEnumerable primes, which for obvious reasons also contains a SortedList _primes.

So when you have to simply iterate through the in-memory collection, use IEnumerable, if you need to do any manipulation with the collection like Dataset and other data sources, use IQueryable

Different implementations of collections kişi be enumerable; using IEnumerable makes it clear that what you're interested in is the enumerability, and hamiş the structure of the underlying implementation of the collection.

It's effectively usage birli documentation of intent; I find that those explicit documentations of intent tend to provide exactly that decoupling you point out.

IEnumerable katışıksız just one method whereas IEnumerator özgü 2 methods (MoveNext and Reset) and a property Current. For easy understanding consider IEnumerable as a box that contains IEnumerator inside it (though derece through inheritance or containment). See the code for better understanding:

Basically it saf a method to get the C# IEnumerable Temel Özellikleri next item in the collection. It doesn't need the whole collection to be in memory and doesn't know how many items are in it, foreach C# IEnumerable Temel Özellikleri just keeps getting the next item until it runs out.

While it might seem that only array C# IEnumerable Kullanımı types kişi make use of this construct, the truth of the matter is

So, the first example evaluates C# IEnumerable Nedir the query immediately by calling ToList and putting the query results in a list.

Nobody mentioned one crucial difference, ironically answered on a question closed bey a duplicated of this. IEnumerable is read-only and List is derece.

List, on the other hand, is a specific implementation of IEnumerable that stores the objects in a specific, known manner. Internally, this may be a very good way to store your values that you expose via IEnumerable, but a List is not always appropriate.

Coming soon: Throughout 2024 we will be phasing out GitHub Issues bey the feedback mechanism for content and replacing it with a new feedback system. For more information see: .

Mafevkdaki hatada Calisan dershaneının bir GetEnumerator derunermediğini belirtiyor. Yani buradan da şu çıailemı yapabiliriz;

My question is that should these classes instead implement the IEnumerable interface, and call GetEnumerator on the List itself.

The most important thing to realize is that, using Linq, the query does hamiş get evaluated immediately. It is C# IEnumerable Temel Özellikleri only run birli part of iterating through the resulting IEnumerable in a foreach - that's what all the weird delegates are doing.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Comments on “Temel İlkeleri C# IEnumerable Nedir”

Leave a Reply

Gravatar