DEğIL HAKKıNDA GERçEKLER BILINEN C# ILIST NEDIR

Değil Hakkında Gerçekler bilinen C# IList Nedir

Değil Hakkında Gerçekler bilinen C# IList Nedir

Blog Article

It's always best to use the lowest base type possible. This gives the implementer of your interface, or consumer of your method, the opportunity to use whatever they like behind the scenes.

Same principle birli before, reversed. Offer the bare asgari that your caller requires. If the caller only requires the ability to enumerate the sequence, only give them an IEnumerable.

Here's an example: I had a project once where our lists got very large, and resulting fragmentation of the large object heap was hurting performance. We replaced List with LinkedList. LinkedList does not contain an array, so all of a sudden, we had almost no use of the large object heap.

Bearing this in mind, it makes most sense to pass types with the least number of external dependencies possible and to return the same. However, this could be different depending on the visibility of your methods and their signatures.

swilliamsswilliams 48.6k2727 gold badges101101 silver badges130130 bronze badges 3 5 why hamiş make it a just a List in the first place? I still don't understand why bonus you get from making it a IList then in the constructor you make it into a List

In some code this birey be quite important and using concrete classes communicates your intent, your need for that specific class. An interface on the other hand says "I just need to call this grup of methods, no C# IList Kullanımı other contract implied."

I thought I'd never need to change from a List but had to later change to use C# IList Neden Kullanmalıyız 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.

OdedOded 496k101101 gold badges890890 silver badges1k1k bronze badges Add a comment  

And, if you don't even need everything in IList you birey always use IEnumerable too. With çağcıl compilers and processors, I don't think there is really any speed difference, so this is more just a matter of style.

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 C# IList Neden Kullanmalıyız to recognize it birli a list.

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.

The most important case for using interfaces over implementations is in the parameters to your API. If your API takes a List parameter, then anyone who uses it başmaklık to use List.

I have two ILists of the same type returned by NHibernate and have C# IList Nedir emerged the two IList into one, hence the need for sorting.

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

Report this page