C# IList Nerelerde Kullanılıyor Için 5-İkinci Trick

It's always best to use the lowest base type possible. This gives the implementer of your interface, or consumer of your method, the opportunity to use whatever they like behind the scenes.

Found this thread while I was looking for a solution to the exact sorun 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 problem today. We have a WCF web service that returns an IList. Hamiş really a big deal until I wanted to sort it.

Kendi derme sınıflarınızı oluştururken gene kullanılabilir şifre yazmanızı sağlar: C# CollectionBase kullanarak genel derlem işlemlerini içeren bir kök sınıf oluşturabilirsiniz.

Basically, I need to see some actual code examples of how using IList would have solved some sıkıntı over just taking List into everything.

I would turn the question around a bit, instead of justifying why you should use the interface over the concrete implementation, try to justify why you would use the concrete implementation rather than the interface. If you dirilik't justify it, use the interface.

Bu şehir, istenmeyenleri azaltmak ciğerin Akismet kullanıyor. Tefsir verilerinizin nasıl ustalıklendiği karşı daha lüks bilim edinin.

In fact, any time you are using reflection IList is more convenient than IList-of-T, since generics and reflection don't play nicely together. It gönül be done, but it is a pain. Unfortunately since IList-of-T doesn't derive from IList there are cases where this birey işleyen - but it C# IList Neden Kullanmalıyız is a good 95% rule.

For example, let's say you have a Person class and a Group class. A Group instance katışıksız many people, so a List here would make sense. When I declare the list object in Group I will use an IList and instantiate it kakım a List.

What US checks and balances prevent the FBI from raiding politicians unfavorable to the C# IList Neden Kullanmalıyız federal government? more hot questions

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

Then I looked C# IList Nerelerde Kullanılıyor in my view(mvc) and found that I actually needed the count method bey I needed to use a for loop. So in my own application I under C# IList Kullanımı estimated what I actually needed how do you anticipate what someone else will need or not need.

In particular, IList lets you use the indexer, and add/remove items; things that IEnumerable don't let you do.

Encapsulation relies on telling clients kakım little about the implementation of your class as possible. If you return a concrete List, you güç't then change to some other better type without forcing all of your clients to re-compile/update.

Leave a Reply

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