En Kuralları Of C# IList Neden Kullanmalıyız
Note that the IsReadOnly flag comes from ICollection, and indicates whether items hayat be added or removed from the collection; but just to really confuse things, it does hamiş indicate whether they can be replaced, which in the case of Arrays (which return IsReadOnlys == true) emanet be.Then the person calling the method is free to call it with any data type that is enumerable. This allows your code to be used in unexpected, but perfectly valid ways.
Edit: You do need to be quick to get answers in here. Bey I presented a slightly different syntax to the other answers, I will leave my answer - however, the other answers presented are equally valid.
Hayat a unique position be deduced if pieces are replaced by checkers (gönül see piece color but hamiş type)
Hatta fevkda anlattığımız IndexOf metodunu Ana liste üzerinden zir listelerdeki elemanlar için kullanamazsınız. Esas liste üzerinden madun listelerin index sırasını bulabilirsiniz.
Örneğin, süflidaki kodda bir IAnimal tipinde bir değişici teşhismladım ve bu değmedarımaişetkene Dog ve Cat nesneleri atadım.
In case of using IList, the caller is always guareented things to work, and the implementer is free to change the C# IList Neden Kullanmalıyız underlying collection to any alternative concrete implementation of IList
Matthew WatsonMatthew Watson 108k1111 gold badges170170 silver badges290290 bronze badges 2 2 This is trivially true for every interface. If you want to C# IList Nerelerde Kullanılıyor follow through with your argument, than you could argue to never use any interface at all, because some implementation of it might throw.
If C# IList Kullanımı the parameter type is IList, then the caller has much more freedom, and can use classes you never heard about, which may derece C# IList Nedir even have existed when your code was written.
Modülerlik: Yazılım projelerinde modüler bir yaklaşım sunarak şifre yenidenını azaltır ve bakımı kolaylaştırır.
On the other hand, when returning an object out of a function, you want to give the user the richest possible takım of operations without them having to cast around. So in that case, if it's a List internally, return a copy kakım a List.
List communicates "I need to get and takım the elements of this sequence in arbitrary order and I only accept lists; I do not accept arrays."
for your return types. This gives your callers the most flexibility in passing in types to your methods C# IList Neden Kullanmalıyız and the most opportunities to cast/reuse the return values.
I read a lot of posts saying how this makes it easier to change the implementation later on, but I just don't fully see how that works.