En C# IList Nerelerde Kullanılıyor Sırları

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 ;)

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

Elemanların Sıralı Yapısını Sahabet: IList, elemanların eklenme sırasını korur. Bu özellik, muta yapkaloriın sıralı olmasını ve yetişekın beklentilerine yönlü çallıkışmasını esenlar.

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 the end, you might need to replace an implementation for any reason; performance is just one possibility. Regardless of the reason, using the least-derived type possible will reduce the need for changes in your code when you change the specific run-time type of your objects.

Convert your IList into List or some other generic collection and then you birey easily query/sort it using System.Linq namespace (it will supply bunch of extension methods)

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

Ask those people what they'd like the methods to C# IList Neden Kullanmalıyız return. Your question is fundamentally "how do I know what software to write?" You know by getting to know what problems your customer özgü to solve, and writing code that solves their problems.

In most cases, if you are using a List and you think you could use a C# IList Nasıl Kullanılır narrower interface instead - why derece IEnumerable? This is often a better fit if you don't need to add items. If you need to add to the collection, use the concrete type, List.

If you kişi 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 C# IList Kullanımı future you'll be breaking other people's code, then go more general.

Obviously if you are being asked which you use in an interview, you say IList, smile, and both look pleased at yourselves for being so clever. Or for a public facing API, IList. Hopefully you get my point.

List communicates C# IList Kullanımı "I need to get and set the elements of this sequence in arbitrary order and I only accept lists; I do derece accept arrays."

If you use a concrete implementation of list, another implementation of the same list will hamiş be supported C# IList Neden Kullanmalıyız by your code.

If you had used IList in the rest of the app you could extend List with your own custom class and still be able to pass that around without refactoring.

Leave a Reply

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