THE ULTIMATE GUIDE TO C# ILIST NERELERDE KULLANıLıYOR

The Ultimate Guide To C# IList Nerelerde Kullanılıyor

The Ultimate Guide To C# IList Nerelerde Kullanılıyor

Blog Article

I toyed with writing an extension method, also with inheriting from IList and implementing my own Sort() method kakım well as casting to a List but none of these seemed overly elegant.

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

The less popular answer is programmers like to pretend their software is going to be re-used the world over, when infact the majority of projects will be maintained by a small amount of people and however birçok interface-related soundbites are, you're deluding yourself.

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.

ToList first? How about returning it? I don't understand what you mean by "method will survive" when using vars? I know it will be a bit more work but won't you just have to change that to the new type kakım well? So maybe IList to IList?

Important Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

StuartLCStuartLC 106k1818 gold badges216216 silver badges289289 bronze badges Add a comment  

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

The idea C# IList Nerelerde Kullanılıyor is that you hide the implementation details from the user, and instead provide them with a stable interface. This is to reduce dependency on details that might change in the future.

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

I know that IList is the interface and List is the concrete type but I still C# IList Kullanımı 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 C# IList Neden Kullanmalıyız use the interface or the concrete type?

rajeshrajesh 39133 silver badges22 bronze badges 1 8 Excellent, clear answer, which I marked birli helpful. However, I would add that for C# IList Neden Kullanmalıyız most developers, most of the time, the tiny difference in yetişek size and performance is not worth worrying about: C# IList Nerelerde Kullanılıyor if in doubt, just use a List.

So typically, your methods should accept and return interfaces for collections. This leaves your own implementation and your callers room to decide on the actual implementation kakım required.

For instance, if you return an IEnumerable, then you are limiting them to iterating -- they emanet't add or remove items from your object, they güç only act against the objects. If you need to expose a collection outside of a class, but don't want to let the caller change the collection, this is one way of doing it. On the other hand, if you are returning an empty collection that you expect/want them to populate, then an IEnumerable is unsuitable.

Report this page