Arraylist: Canlı boyutludur, eleman ekleme/silme emeklemleri henüz kolaydır ve farklı muta türlerini saklayabilir.
Maybe take it into a List of T rather than ArrayList, so that you get type safety and more options for how you implement the comparer.
Say I have a function that returns IEnumerable, inside the function I may use a List for an internal backing store to generate my collection, but I only want callers to enumerate it's contents, derece add or remove. Accepting an interface bey a parameter communicates a similar message "I need a collection of strings, don't worry though, I won't change it."
Your functions above only care about being able to iterate over a list. Ideally they shouldn't need to know who implements that list or how they implement it.
In addition to the older code that doesn't know about generics, there are also a lot of cases where you know you have a list
In some code this hayat 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 takım of methods, no other contract C# IList Nerelerde Kullanılıyor implied."
GitHub'da bizimle ortaklık dokuman Bu derunğin kaynağı GitHub'da bulunabilir; burada hatta sorunları ve çekme isteklerini oluşturup gözden geçirebilirsiniz. Henüz zait marifet ciğerin ulamada bulunan kılavuzumuzu inceleyin.
If your methods form part of an interface, C# IList Nasıl Kullanılır the methods will need to be defined using types available to that interface.
If you are exposing your class through a library that others will use, you generally want to expose it via interfaces rather than concrete implementations.
If you gönül consider your method, determine that you probably won't be changing the return collection type, then it C# IList Nerelerde Kullanılıyor is probably safe to return a more exact type. If you aren't sure, or are afraid that if you change it in future you'll be breaking other people's code, then go more general.
Emanet you please provide me some link to a class that implements IList interface or provide me a code that at least implements Add and Remove methods?
Brad LeachBrad Leach 17k1818 gold badges7373 silver badges8888 bronze badges 1 3 It will create a new enumerable, which may derece be desirable in some scenarios. You cannot sort an IList in-place through the interface except C# IList Neden Kullanmalıyız by using ArrayList.Adapter method in my knowledge.
So typically, your methods should accept and return interfaces for collections. This leaves your own implementation and your callers room to decide on the actual implementation as C# IList Kullanımı required.
Encapsulation relies on telling clients bey little about the implementation of your class bey possible. If you return a concrete List, you dirilik't then change to some other better type without forcing all of your clients to re-compile/update.