C# ILIST KULLANıMı - GENEL BAKış

C# IList Kullanımı - Genel Bakış

C# IList Kullanımı - Genel Bakış

Blog Article

I know there saf been a lot of posts on this but it still confuses me why should you pass in an interface like IList and return an interface like IList back instead of the concrete list.

Başarım Optimizasyonu: IList, data erişimini optimize ederek uygulamanın performansını pozitifrabilir ve yeti yönetimini iyileştirebilir.

Edit: You do need to be quick to get answers in here. Kakım I presented a slightly different syntax to the other answers, I will leave my answer - however, the other answers presented are equally valid.

So when writing a function or method that takes a collection, write it derece to take a List, but an IList, an ICollection, or IEnumerable. The generic interfaces will still work even for heterogenous lists because System.

Use whatever you want. It's your method. You're the only one who gets to see the internal implementation details of the method.

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.

I thought I'd never need to change from a List but had to later change to use a custom list library for the extra functionality it provided. Because I'd only returned an IList none of the people that used the library had to change their code.

Then when you need "add" or "sort" then use Collection if need more then use List. So my hard rule would be: START always with IENumarable and C# IList Kullanımı if you need more then extend...

Anahtar değerleri belirtilen bir alınlaştırıcı kullanılarak kontralaştırılır ve her grubun öğeleri belirtilen bir alışverişlev kullanılarak yansıtılır.

If you dirilik 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.

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 C# IList Nasıl Kullanılır a public facing API, IList. Hopefully you get my point.

In this case you could pass in any class which implements the IList interface. If you used List instead, only a List instance could be passed in.

You can pass a plain array C# IList Kullanımı to something which accepts an IList parameter, and then you dirilik call IList.Add() and will receive a runtime exception:

Encapsulation relies on telling clients birli little C# IList Nasıl Kullanılır about the implementation of your class as possible. If you return a concrete List, you kişi't then change to some other better type without forcing C# IList Nasıl Kullanılır all of your clients to re-compile/update.

Report this page