5 Basit Teknikleri için C# IList Nedir

driisdriis 163k4545 gold badges268268 silver badges343343 bronze badges 3 Sorry, but even now there are plenty of uses for library code to use IList (non-generic). Anyone who says otherwise hasn't suffered enough reflection / veri-binding / etc ;)

But far more importantly, if you are accepting an IList kakım a parameter you'd better be careful, because IList and List do hamiş behave the same way. Despite the similarity in name, and despite sharing an interface

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

The following example demonstrates the implementation of the IList interface to create a simple, fixed-size list.

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

Yes, you may never change that veri type from a List but you yaşama be sure that if you have to. Your code is ready for it.

The class name List may be changed in next .kemiksiz framework but the interface is never going to change bey interface is contract.

Don't you know in advance if your method needs a list that sevimli take additional members; don't you specify that in the method signature? What exactly were you going to do if you were passed a read only list like int[]?

the method, it güç make a huge difference -- if they have an array and you're asking for a list, they have to change the array to a list or v.v. whenever calling the method, a total waste of time from both a C# IList Nedir programmer and performance POV.

If you can consider your method, determine that you probably won't be changing the return collection type, then it is probably safe to return a more exact type. If you aren't sure, or are afraid that if you change it in future you'll be breaking other people's code, then go more general.

kemiller2002kemiller2002 115k2828 C# IList Nedir gold badges198198 silver badges253253 bronze badges Add a comment  

I leave this up to show that if you needed to do it (e.g. the off chance a third party library returned C# IList Kullanımı a List that you needed to convert for another 3rd party library), you yaşama do it this C# IList Nedir way.

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

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

Leave a Reply

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