C# IEnumerable Temel Özellikleri - Genel Bakış

[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.

Umarım bu laf için kafanızda bir görüş oluşturabilmişimdir.Bu yazı yürekin oluşturduğum projenin kodlarını GitHub hesabımdaki “MyArticlesCodes” repository’sinde bulabilirsiniz.

g. executing SQL on GarbageCollected contexts). I would say that ICollection is every thing you said apart from the "lazy evaluation" and we should be using that, especially if the data has already been enumerated once!

Analogy: Imagine you are a detective on an aeroplane . You need to work your way through all the passengers to find your suspect.

An IEnumerator is a thing that kişi enumerate: it başmaklık the Current property and the MoveNext and Reset methods (which in .Kemiksiz code you probably won't call explicitly, though you could).

The syntax (which you rarely see because there are prettier ways to do it) for moving through a collection that implements IEnumerable is:

So if I am going through C# IStructuralComparable Nasıl kullanılır all the items on ebay, one at a time would be something even a small computer yaşama handle, but ".ToList()" would surely run me out of memory, no matter how big my computer was. No computer dirilik by itself contain and handle such a huge amount of veri.

Kısaca uzun lafın kısası IEnumerable interface’in implement edilmiş olduğu bir class üzerine GetEnumerator metodu uygulattırılır. Haliyle yukarıda yapmış C# IStructuralComparable nerelerde kullanılıyor olduğumız kadar ilişkin metodu manuel olarak yazmaktan ve olası yazım hatalarından bizleri kurtarmaktadır.

Yield ile kendimiz named iteretor'ler oluşturabiliriz. Örneğin programımızın 750TL den daha pahalı ürünleri getirmesini istiyoruz:

There are pros and cons to both. If you call ToList, you may remove some mystery birli to when the query gets executed. If you stick to IEnumerable, you get the C# IStructuralComparable nerelerde kullanılıyor advantage that the program doesn't do any work until it's actually required.

It is cleaner, your users don't get a list where they shouldn't (they could cast it to C# IStructuralComparable Nasıl kullanılır a Listafter all) and you don't need to create C# IStructuralComparable Temel Özellikleri a Listobject.

Generally, don't worry about what's actually in the IEnumerables, kakım it will be completely different from your actual code. Only worry about the actual output when you iterate over it :)

Reed CopseyReed Copsey 561k7979 gold badges1.2k1.2k silver badges1.4k1.4k bronze badges 3 2 I agree strongly with your point about decoupling from the implementation, but I also think there's a point for making clear the expected usage; even if I have a List, referring to it kakım IEnumerable makes it clear that the functionality I'm expecting from the collection in that usage is the enumerability functionality, and not any of the other List functionality.

IEnumerable interface’i ile bir derslik itere edilebilir hale getiriliyor, bu muamelat ortamında GetEnumerator metodu sınıfa implement ediliyordu. IEnumerator interface’i ise iterasyon özelliği kazandıracak ve iterasyon anlayışleminde kullanılacak elemanları ve özellikleri çitndırmaktadır.

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

Comments on “C# IEnumerable Temel Özellikleri - Genel Bakış”

Leave a Reply

Gravatar