BENIM C# ILIST NEDEN KULLANMALıYıZ BAşLARKEN ÇALışMAK

Benim C# IList Neden Kullanmalıyız Başlarken Çalışmak

Benim C# IList Neden Kullanmalıyız Başlarken Çalışmak

Blog Article

We needed the list indexer infrequently, so the inefficiency was not a sıkıntı. If it had been, we could have provided some other implementation of IList, perhaps as a collection of small-enough arrays, that would have been more efficiently indexable while also avoiding large objects.

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?

Also, it casts IList to IList which özgü the potential to be dangerous. In most cases that I have seen, List which implements IList is used behind the scenes to implement IList, but this is not guaranteed and gönül lead to brittle code.

Kendi derme sınıflarınızı oluştururken yeni baştan kullanılabilir kod yazmanızı katkısızlar: C# CollectionBase kullanarak umumi derme nöbetlemlerini muhtevaermiş bir anayasa dershane oluşturabilirsiniz.

Basically, I need to see some actual code examples of how using IList would have solved some sıkıntı over just taking List into everything.

so its safety for you and freedom to the coder who is writing concrete implementation to change or add more functionality to his concrete class.

The cost to do this is C# IList Nedir minimal, why hamiş save yourself the headache later? It's what the interface principle is all about.

Don't you know in advance if your method needs a list that kişi take additional members; don't you specify that in the method signature? What exactly were you going to do if you were passed a read only list like int[]?

Whether you return an Interface or a concrete type depends upon what you want to let your callers do with the object you C# IList Nasıl Kullanılır 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).

Want to improve this question? Update the question so it emanet be answered with facts and citations by editing this post.

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, C# IList Nerelerde Kullanılıyor IList. Hopefully you get my point.

rajeshrajesh 39133 silver badges22 bronze badges 1 8 Excellent, clear answer, which I marked bey helpful. However, I would add that for most developers, most of the time, the tiny difference in program size and performance is hamiş worth worrying C# IList Nasıl Kullanılır about: if in doubt, just use a List.

If you use a concrete implementation of list, another implementation C# IList Kullanımı of the same list will derece be supported by your code.

There is a complication though that dynamic can't see explicit implementations, so something emanet implement IList and IList-of-T and yet still be completely unusable from dynamic.

Report this page