Açıklaması C# IList Nasıl Kullanılır Hakkında 5 Basit Tablolar
Açıklaması C# IList Nasıl Kullanılır Hakkında 5 Basit Tablolar
Blog Article
I know there katışıksız been a lot of posts on this but it still confuses me why should you pass in an interface like IList and return an interface like IList back instead of the concrete list.
Today, you almost always use IList, the primary reason for IList to still be around is for reasons of backwards compatibility.
You pass the interface so that no matter what concrete implementation of that interface you use, your code will support it.
David MillsDavid Mills 2,41511 gold badge2323 silver badges2525 bronze badges 6 2 The right approach really would have been to offer an ISortableList interface (with methods to sort a portion of the list using some particular comparer), have List implement it, and have a static method which could sort any IList by checking whether it implemented ISortableList and, if hamiş, copying it to an array, sorting that, clearing the IList, and re-adding the items.
Basically, I need to see some actual code examples of how using IList would have solved some problem 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.
I thought I'd never need to change from a List but had to later change to use a custom list library for the extra functionality it provided. Because I'd only returned an IList none of the people that used the library had to C# IList Neden Kullanmalıyız change their code.
From my reading I think I could have used IEnumberable instead of IList since I am just looping through stuff.
but my problem is that i am hamiş understanding what is its use and when to use it . So i hope that anyone can help me . Thanks .
C# List bağırsakindeki C# IList Nedir verileri yazdırmak ciğerin hordaki iki döngüden biri kullanılarak değerleri ekrana yazdırma fiillemi strüktürlabilir.
Adidaki şekilde Kisi adında oluşturduğumuz dershaneı oluşturduğumuz liste nesnesine ekleyelim.
Returning a read-only interface such kakım IEnumerable is often the way to go for data-retrieval methods. Your consumer sevimli project it into a richer type kakım-needed.
This will help if you decide to change the implementation of your class later C# IList Neden Kullanmalıyız to use a different concrete class. C# IList Nasıl Kullanılır In that case the users of your library won't need to update their code since the interface doesn't change.
This works, because only the outer list is created in the first place. C# IList Kullanımı You emanet then insert individual items that are compatible with IList: