Greatest Kılavuzu C# IList Kullanımı için

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

1 @supercat: What could ISortableList offer that's hamiş already in IList? Or, asked differently, why couldn't an IList be sorted in-place without re-adding the items by your imagined static method?

Bir dahaki sefere tefsir yapmış olduğumda kullanılmak üzere kademı, elektronik posta adresimi ve web kent adresimi bu tarayıcıya kaydet.

It's more nuanced than that. If you are returning an IList kakım part of the public interface to your library, you leave yourself interesting options to perhaps make a custom list in the future.

In this specific case since you're essentially talking about a language construct, not a custom one it generally won't matter, but say for example that you found List didn't support something you needed.

In some code this dirilik be quite important and using concrete classes communicates your intent, your need for that specific class. An interface on the other hand says "I just need to call this kaş of methods, no other contract implied."

GitHub'da bizimle ortaklaşa iş bünyen Bu hapishaneğin kaynağı GitHub'da bulunabilir; burada üste problemlerı ve çekme isteklerini oluşturup gözden geçirebilirsiniz. Henüz bir küme selen bâtınin ulamada bulunan kılavuzumuzu inceleyin.

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

Whether you return an Interface or a concrete type depends upon what you want to let your callers do with the object you C# IList Nedir 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 easily use a portion of the objects functionality (and of course whether you WANT them to be making C# IList Neden Kullanmalıyız full use of the object).

List implements those nene methods (derece including extension methods), on tamamen of that it saf about C# IList Neden Kullanmalıyız 41 public methods, which weighs in your consideration of which one to use in your application.

By asking for more than you need, you (1) make the caller do unnecessary work C# IList Nerelerde Kullanılıyor to satisfy your unnecessary demands, and (2) communicate falsehoods to the reader. Ask only for what you're going to use. That way if the caller has a sequence, they don't need to call ToList on it to satisfy your demand.

Brad LeachBrad Leach 17k1818 gold badges7373 silver badges8888 bronze badges 1 3 It will create a new enumerable, which may not be desirable in some scenarios. You cannot sort an IList in-place through the interface except by using ArrayList.Adapter method in my knowledge.

Özel koleksiyonlar oluşturmanıza imkân tanır: ölçünlü derme sınıfları ihtiyaçlarınızı zıtlamıyorsa, kendi özel koleksiyonlarınızı C# CollectionBase kullanarak oluşturabilirsiniz. Bu, bilgi binalarınızı istediğiniz şekilde özelleştirmenizi sağlamlar.

additional advantage is that your code is safe from any changes to concrete class bey you are subscribing to only few of the methods of concrete class and those are the ones that C# IList Nerelerde Kullanılıyor are going to be there kakım long bey the concrete class inherits from the interface you are using.

Leave a Reply

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