EN IYI TARAFı C# ILIST KULLANıMı

En iyi Tarafı C# IList Kullanımı

En iyi Tarafı C# IList Kullanımı

Blog Article

You cannot predict the future. Assuming that a property's type will always be beneficial as a List is immediately limiting your ability to adapt to unforeseen expectations of your code.

Lütfen adidaki kutuya şikayetinizin detaylarını edebiyat. Şikayetinizi değerlendirildikten sonrasında size fen vereceğiz.

So I came across an interesting sıkıntı today. We have a WCF web service that returns an IList. Derece really a big deal until I wanted to sort it.

All concepts are basically stated in most of the answers above regarding why use interface over concrete implementations.

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.

The speed difference is sufficiently great that in many cases it may be faster to copy a list to an array, sort the array, and copy the list back, than to try to have a sort routine process the list in place.

In case of using IList, the caller is always guareented things to work, and the implementer is free to change the underlying collection to any alternative concrete implementation of IList

If you specify your methods to return an interface that means you are free to change the exact implementation later on without the consuming method ever knowing.

If you started with a concrete type and you decided to change to another one, even if it uses the same interface, you're going to break someone else's code unless you started off with an interface or abstract base type. Share C# IList Kullanımı Improve this answer Follow

What US checks and balances prevent the FBI from raiding politicians unfavorable to the federal government? more hot questions

private List _numbers; // callers emanet add/update/remove elements, but cannot reassign a new list to this property

Returning a read-only interface such birli IEnumerable is often the way to go for C# IList Neden Kullanmalıyız veri-retrieval methods. Your consumer güç project it into a richer type birli-needed.

This will help if you decide to change the implementation of your class later to use a different concrete C# IList Kullanımı class. In that case the users of your library won't need to update their code since the interface doesn't change.

ahead of time. Veri-binding is a classic example here; a C# IList Nerelerde Kullanılıyor DataSource property usually checks for C# IList Nerelerde Kullanılıyor IList (and IListSource, typically) and then looks at the objects to see what properties are available. It kişi't use generics in this case.

Report this page