DETAYLAR, KURGU VE C# ILIST NASıL KULLANıLıR

Detaylar, Kurgu ve C# IList Nasıl Kullanılır

Detaylar, Kurgu ve C# IList Nasıl Kullanılır

Blog Article

I know there başmaklık 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.

Arec BarrwinArec Barrwin 61.8k99 gold badges3030 silver badges2525 bronze badges 14 71 I have to disagree with your sardonic answer. I don't totally disagree with the sentiment of over-architecture being a real sıkıntı. However I think that especially in the case of collections that interfaces really shine.

Elemanların Sıralı Yapkaloriı Koruma görevlisi: IList, elemanların eklenme sırasını korur. Bu özellik, done yapkaloriın sıralı olmasını ve yetişekın beklentilerine isabetli çkırmızıışmasını katkısızlar.

A List object allows you to create a list, add things to it, remove it, update it, index into it and etc. List is used whenever you just want a generic list where you specify object type in it and that's it.

In addition to the older code that doesn't know about generics, there are also a lot of cases where you know you have a list

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 kişi't justify it, use the interface.

use LINQ to C# IList Neden Kullanmalıyız perform the conversion of your existing List when you return it - but it would be better to just create a more appropriate type to start with, kakım shown above.

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

Whether you return an Interface or a concrete type depends upon what you want to let your callers do with the object you created -- this is an API design decision, and there's no hard and fast rule. You have to weigh their ability to make full use of the object against their ability to easily use a portion of the objects functionality (and of course whether you WANT them to be making full use of the object).

It really comes down to the kind of functionality you need. I'd suggest using the List class in most cases. IList is best for when you need to make a custom array that could have some very specific rules that you'd like to encapsulate within a collection so you don't repeat yourself, but still want .Kemiksiz to recognize it kakım a list.

However, this makes the method more fragile, as any change to the returned object type C# IList Nasıl Kullanılır may break the calling code. In practice though, that generally isn't a major mesele.

Collaborate with us on GitHub The source for this content birey be found on GitHub, C# IList Nerelerde Kullanılıyor where you dirilik also create and review issues and pull requests. C# IList Kullanımı For more information, see our contributor guide.

This will help if you decide to change the implementation of your class later C# IList Nerelerde Kullanılıyor to use a different concrete class. In that case the users of your library won't need to update their code since the interface doesn't change.

So I have been playing around with some of my methods on how to do this. I am still derece sure about the return type(if I should make it more concrete or an interface).

Report this page