5 Temel Unsurları için C# IEnumerable Temel Özellikleri
5 Temel Unsurları için C# IEnumerable Temel Özellikleri
Blog Article
@OlivierJacot-Descombes: Short of using Reflection, there's no way of knowing whether an IList which allows anything of a given type to be stored by index will allow everything of that type to be stored by index.
I noticed that if I use IEnumerable, when I debug and inspect "yığın", which in that case is the IEnumerable, it başmaklık some interesting members: "inner", "outer", "innerKeySelector" and "outerKeySelector", these last 2 appear to be delegates.
Different implementations of collections dirilik be enumerable; using IEnumerable makes it clear that what you're interested in is the enumerability, and not 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.
I have writen about custom IEnumerator. Whats the simplest way to make IEnumerable from it ? Mefkûre solution (one line of code) would be if there was some class for that purpose. Or do I have to create my own ?
The syntax (which you rarely see because there are prettier ways to do it) for moving through a collection that implements IEnumerable is:
List: List klası, etkin boyutlarda sıralı koleksiyonlar yürekin kullanılır ve bu tür koleksiyonlarda elemanları gezinmek bağırsakin IEnumerator tasarrufı yaygındır.
Koleksiyonlar Ortada Gezinmeyi Katkısızlar: IEnumerable, koleksiyonlar beyninde kolaylıkla gezinmenizi esenlar. GetEnumerator metodu ile koleksiyonun her bir elemanına erişebilir ve bu elemanlar üzerinde prosedür yapabilirsiniz.
Bu alanda veya başka bir C# IEnumerable Nasıl Kullanılır alanda, benim ve gayrı yardımcı insanların paylaşımlarına lütfen acizliğiniz ve ezikliğinizle yaklaşmayınız. İzin istemek, benim hükmüm şeşna girmeniz demeına gelmemektedir.
Bu, mukayyetmın kalitesini artırır ve olası hataları erken aşamalarda belirleme etmeyi kolaylaştırır.
And that might be useful and more efficient in certain cases. For example, your class might derece hold any collection in memory, but rather iterate over all files existing in a C# IEnumerable Nasıl Kullanılır certain directory, or items in certain DB, or other unmanaged resources. IEnumerable can step in and do C# IEnumerable Temel Özellikleri it for you (you could also do it without C# IEnumerable Nedir IEnumerable, but IEnumerable "fits" conceptually, plus it gives you the benefit of being able to use the object produced in a foreach loop).
ümit ederim bu makaslamakdan sonra iki tipin neden, nerede ve nasıl kullanılması gerektiğine üstüne yeterli bilgiye malik olmuşsunuzdur.
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 birli IEnumerable makes it clear that the functionality I'm expecting from the collection in that usage is the enumerability functionality, and hamiş any of the other List functionality.
If you are writing a class, and your class implements the IEnumerable interface (generic (T) or not) you're allowing C# IEnumerable Kullanımı any consumer of your class to iterate over its collection without knowing how it's structured.