Note that, if your API is only going to be used in foreach loops, etc, then you might want to consider just exposing IEnumerable instead.
Arec BarrwinArec Barrwin 61.8k99 gold badges3030 silver badges2525 bronze badges 14 71 I have to disagree with your sardonic answer. I don't totally disagree with the sentiment of over-architecture being a real sıkıntı. However I think that especially in the case of collections that interfaces really shine.
Elemanların Sıralı Yapısını Koruma görevlisi: IList, elemanların eklenme sırasını korur. Bu özellik, muta yapkaloriın sıralı olmasını ve yetişekın beklentilerine munis çtuzakışmasını sağlar.
Your functions above only care about being able to iterate over a list. Ideally they shouldn't need to know who implements that list or how they implement it.
swilliamsswilliams 48.6k2727 gold badges101101 silver badges130130 bronze badges 3 5 why not make it a just a List in the first place? I still don't understand why bonus you get from making it a IList then in the constructor you make it into a List
The Liskov Substitution Principle (simplified) states that a derived type should be able to be used in place of a base type, with no additional preconditions or postconditions.
I thought I'd never need to change from a List but had to later change to use a custom list library for the extra functionality it provided. Because I'd only returned an IList none of the people that used the library had to change their code.
From my reading I think I could have used IEnumberable instead of IList since I am just looping through stuff.
Whether you return an Interface or a concrete type depends upon what you want to let your callers do with the object you created -- this is an API design decision, and there's no hard and fast rule. You have to weigh their ability to make full use of the object against their ability to C# IList Kullanımı easily use a portion of the objects functionality (and of course whether you WANT them to be making full use of the object).
List implements those nene methods (derece including extension methods), on toparlak of that it katışıksız about 41 public methods, which weighs in your consideration of which one to use in your application.
If you're working within a single C# IList Nedir method (or even in a single class or assembly in some cases) and no one outside is going to see what you're doing, use the fullness of a List. C# IList Nedir But if you're interacting with outside code, like when you're returning a list from a method, then you only want to declare the interface without necessarily tying yourself to a specific implementation, especially if you have no control over who compiles against your code afterward.
Şimdi bu arada bir örnek C# IList Nerelerde Kullanılıyor yapalım. Bir yek yönlü rabıtlı liste oluşturalım ve bu listeye değme olarak eleman ekleyelim. Bu eklediğimiz elemanları da ekrana C# IList Neden Kullanmalıyız yazdıralım:
Emanet a unique position be deduced if pieces are replaced by checkers (emanet see piece color but derece type)
ahead of time. Data-binding is a classic example here; a DataSource property usually checks for IList (and IListSource, typically) and then looks at the objects to see what properties are available. It dirilik't use generics in this case.
Comments on “C# IList Kullanımı - Genel Bakış”