HAKKıNDA HERşEY C# ILIST NERELERDE KULLANıLıYOR

Hakkında herşey C# IList Nerelerde Kullanılıyor

Hakkında herşey C# IList Nerelerde Kullanılıyor

Blog Article

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 / data-binding / etc ;)

Then the person calling the method is free to call it with any veri type that is enumerable. This allows your code to be used in unexpected, but perfectly valid ways.

Using IList instead of List makes writing unit tests significantly easier. It allows you to use a 'Mocking' library to pass and return veri.

If you think that interfaces are useful only for building over-sized, grandiose architectures and have no place in small shops, then I hope that the person sitting across from you in the interview isn't me.

This will allow me to do generic processing on almost any array in the .Kupkuru framework, unless it uses IEnumerable and not IList, which happens sometimes.

Yes, you may never change that veri type from a List but you gönül be sure that if you have to. Your code is ready for it.

Most app-level code (i.e. the everyday code that ou write for your application) should probably focus on the generic versions; however there is also a lot of infrastructure code around that must use reflection.

If your methods form part of an interface, the methods will need to be defined using types C# IList Nedir available to that interface.

In most cases, if you are using a List and you think you could use a narrower interface instead - why hamiş 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.

class Kisi string ad; string soyad; public string C# IList Neden Kullanmalıyız Ad get return ad; grup ad = value; public string Soyad get return soyad; grup soyad = value;

It C# IList Neden Kullanmalıyız is like this other question. The other question shares a lot of common ground, but is arguably derece a true duplicate. In either case though, this is hamiş opinion-based. What may have happened is that the closer might have just C# IList Nerelerde Kullanılıyor looked at this question's title, without reading the question itself. The body is objective.

rajeshrajesh 39133 silver badges22 bronze badges 1 8 Excellent, clear answer, which I marked birli helpful. However, I would add that for most developers, most of the time, the tiny difference in yetişek size and performance is derece worth worrying about: if in doubt, just use a List.

This will help if you decide to change the implementation of your class later 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.

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 can only act against the objects. If you need to expose a collection outside C# IList Neden Kullanmalıyız 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