C# IList Neden Kullanmalıyız Seçenekler

Wiki Article

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

Found this thread while I was looking for a solution to the exact mesele described in the original post. None of the answers met my situation entirely, however. Brody's answer was pretty close. Here is my situation and solution I found to it.

So I came across an interesting mesele today. We have a WCF web service that returns an IList. Not really a big deal until I wanted to sort it.

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.

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.

Architecture Astronauts. The chances you will ever write your own IList that adds anything to the ones already in the .Safi C# IList Nerelerde Kullanılıyor framework are so remote that it's theoretical jelly tots reserved for "best practices".

 

Don't you C# IList Kullanımı know in advance if your method needs a list that yaşama take additional members; don't you specify that in the method signature? What exactly were C# IList Kullanımı you going to do if you were passed a read only list like int[]?

And, if you don't even need everything in IList you kişi always use IEnumerable too. With modern compilers and processors, I don't think there is really any speed difference, so this is more just a matter of style.

It really comes down to the kind of functionality you need. I'd suggest using the List class in most cases. IList is best for when you need to make a custom array that could have some very specific rules that you'd like to encapsulate within a collection so you don't repeat yourself, but still want .Kemiksiz to recognize it as a list.

Aşağıdaki şekilde Kisi adında oluşturduğumuz dershaneı oluşturduğumuz liste nesnesine ekleyelim.

Benefit of using an Interface is that C# IList Neden Kullanmalıyız you get to implement your functionality or better yet, the only functionality you require. So, if iteration/enumeration is required only, then there is no need for the Sort, Add methods.

Unless you have a very compelling reason to do so, your best bet will be to inherit from System.Collections.ObjectModel.Collection since it katışıksız everything you need.

There is C# IList Nerelerde Kullanılıyor a complication though that dynamic güç't see explicit implementations, so something hayat implement IList and IList-of-T and yet still be completely unusable from dynamic.

Report this wiki page