Detaylar, Kurgu ve C# IList Nasıl Kullanılır

The above is an IList itself as this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but derece sure. Still, I birey't figure out what the user would 100% need(that's where returning a concrete saf an advantage over).

Bir dahaki sefere versiyon yaptığımda kullanılmak üzere adımı, elektronik posta adresimi ve web şehir adresimi bu tarayıcıevet kaydet.

Interface’ler üzerine elan bir tomar malumat iktisap etmek isterseniz, zirdaki kaynaklara oda atabilirsiniz:

Kendi derlem sınıflarınızı oluştururken yine kullanılabilir kod yazmanızı sağlamlar: C# CollectionBase kullanarak umumi derlem fiillemlerini sineaziz bir taban sınıf oluşturabilirsiniz.

This will allow me to do generic processing on almost any array in the .Kupkuru framework, unless it uses IEnumerable and derece IList, which happens sometimes.

Convert your IList into List or some other generic collection and then you gönül easily query/sort it using System.Linq namespace (it will supply bunch of extension methods)

You may not ever need that option, but it's an argument. I think it's the entire argument for returning the interface instead of the concrete type. It's worth mentioning, but in this case it başmaklık a serious flaw.

3 @phoog: Considering where Eric is coming C# IList Kullanımı from, it wouldn't be surprising he is more cautious about breaking changes. But it is definitely a valid point.

In most cases, if you are using a List and you think you could use a narrower interface instead - why not IEnumerable? This is often a better fit if you don't C# IList Nedir need to add items. If you need to add to the collection, use the concrete type, C# IList Neden Kullanmalıyız List.

If you code your own class implementing the IList interface, make sure you also implement the non-generic IList interface, or the code will yapan with a class cast exception.

I know that IList is the interface and List is the concrete type but C# IList Kullanımı I still don't know when to use each one. What I'm doing now is if I don't need the Sort or FindAll methods I use the interface. Am I right? Is there a better way to decide when to use the interface or the concrete type?

rajeshrajesh 39133 silver badges22 bronze badges 1 8 Excellent, clear answer, which I marked kakım helpful. However, I would add that for most developers, most of the time, the tiny difference in program size and performance is not worth worrying about: if in doubt, just use a List.

In particular, IList lets you use the C# IList Nasıl Kullanılır indexer, and add/remove items; things that IEnumerable don't let you do.

So I have been playing around with some of my methods on how to do this. I am still not sure about the return type(if I should make it more concrete or an interface).

Leave a Reply

Your email address will not be published. Required fields are marked *