Açıklaması C# IList Nasıl Kullanılır Hakkında 5 Basit Tablolar

I toyed with writing an extension method, also with inheriting from IList and implementing my own Sort() method bey well birli casting to a List but none of these seemed overly elegant.

1 @supercat: What could ISortableList offer that's derece already in IList? Or, asked differently, why couldn't an IList be sorted in-place without re-adding the items by your imagined static method?

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 hamiş contain an array, so all of a sudden, we had almost no use of the large object heap.

It's more nuanced than that. If you are returning an IList birli part of the public interface to your library, you leave yourself interesting options to perhaps make a custom list in the future.

In this specific case since you're essentially talking about a language construct, not a custom one it generally won't matter, but say for example that you found List didn't support something you needed.

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

The cost to do this is minimal, why derece save yourself the headache later? It's what the interface principle is all about.

You dirilik look at this argument from several angles including the one of a purely OO C# IList Nasıl Kullanılır approach which says to yetişek against an Interface not an implementation. With this thought, using IList follows the same principal kakım passing around and using Interfaces that you define from scratch. I also believe in the scalability and flexibility factors provided by an Interface in general. If a class implmenting C# IList Nerelerde Kullanılıyor IList C# IList Nedir needs to be extended or changed, the consuming code does not have to change; it knows what the IList Interface contract adheres to.

the method, it sevimli make a huge difference -- if they have an array and you're asking for a list, they have to change the array to a list or v.v. whenever calling the method, a total waste of time from both a programmer and performance POV.

Then later if you decide C# IList Nedir to convert the actual data store from a List to a Dictionary and expose the dictionary keys kakım the actual value for the property (I have had to do exactly this before). Then consumers who have come to expect that their changes will be reflected inside of your class will no longer have that capability. That's a big sorun! If you expose the List kakım an IEnumerable you can comfortably predict that your collection is hamiş being modified externally. That is one of the powers of exposing List birli any of the above interfaces.

 

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.

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 C# IList Nerelerde Kullanılıyor code since the interface doesn't change.

Fakat list kullanmaında kapasite belirtilmez kullanıcak veriler sınırlı ise örneğin haftanın günleri ise bunları diziye teşhismlayabiliriz ancak kullanılacak veriler araba plakası,telefon numarası kadar adetsı gizli veriler kullanıcak ise mutlaka list olarak saklanmalıdır.Şimdi C#’ta list kullanmaı kucakin örneğimize bakalım.

Leave a Reply

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