You cannot predict the future. Assuming that a property's type will always be beneficial bey a List is immediately limiting your ability to adapt to unforeseen expectations of your code.
Bir dahaki sefere değerlendirme yapmış olduğumda kullanılmak üzere etapı, e-posta adresimi ve web kent adresimi bu tarayıcıevet kaydet.
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.
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.
I tend to follow Jeffrey's advice for internal code, but for a public library, I would probably be more inclined to follow Eric's.
Yes, you may never change that data type from a List but you birey be sure that if you have to. Your code is ready for it.
In case of using IList, the caller is always guareented things to work, and the implementer is free to change the underlying collection to any alternative concrete implementation of IList
Matthew WatsonMatthew Watson 108k1111 gold badges170170 silver badges290290 bronze badges 2 C# IList Kullanımı 2 This is trivially true for every interface. If you want to follow through with your argument, than you could argue to never use any interface at all, because some implementation of it might throw.
If you started with a concrete type and you decided to change to another one, even if it uses the same interface, you're going to break someone else's code unless you started off with an interface or abstract base type. Share Improve this answer Follow
If you code your own class implementing the IList interface, make C# IList Neden Kullanmalıyız sure you also implement the non-generic IList interface, or the code will yapan with a class cast exception.
private List _numbers; // callers sevimli add/update/remove C# IList Nedir elements, but cannot reassign a new list to this property
List communicates "I need C# IList Neden Kullanmalıyız to get and seki the elements of this sequence in arbitrary C# IList Kullanımı order and I only accept lists; I do derece accept arrays."
If you use a concrete implementation of list, another implementation of the same list will not be supported by your code.
The other general reason for using interfaces is to expose the asgari amount of knowledge necessary to the user of an object. Consider the (contrived) case where I have a veri object that implements IList.