C# ILIST NERELERDE KULLANıLıYOR - GENEL BAKış

C# IList Nerelerde Kullanılıyor - Genel Bakış

C# IList Nerelerde Kullanılıyor - Genel Bakış

Blog Article

The above is an IList itself kakım this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but derece sure. Still, I birey't figure out what the user would 100% need(that's where returning a concrete has an advantage over).

1 @supercat: What could ISortableList offer that's hamiş 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?

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.

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.

Kemiksiz 4.6 (and it will likely be caught by the compiler). But there sevimli be more insidious cases, such kakım passing a C# array as a IList. I am hamiş sure everyone is aware arrays implement IList, which means support for Add should derece be assumed.

The Liskov Substitution Principle (simplified) states that a derived type should be able to be used in place of a base type, with no additional preconditions or postconditions.

use LINQ to perform the conversion of your existing List when you return it - but it would be better to just create a more C# IList Neden Kullanmalıyız appropriate type to start with, bey shown above.

 

For example, let's say you have a Person class and a Group class. A Group instance özgü many people, so a List here would make sense. When I declare the list object in Group I will use C# IList Nerelerde Kullanılıyor an IList and instantiate it bey a List.

tranmqtranmq 15.5k33 gold badges3232 silver badges2727 bronze badges 6 But in this case I sevimli't bind my collection to DataGridView rather I have to expose the _list member in C# IList Neden Kullanmalıyız MyCollection.

I know that IList is the interface and List is the concrete type but I still don't know when to use each one. What I'm doing now is if I don't need the Sort or FindAll methods I use the interface. Am I right? Is there a better way to decide when to use the interface or the concrete type?

The most important case for using interfaces over implementations is in the parameters to your API. If your API takes C# IList Nedir a List parameter, then anyone who uses it başmaklık to use List.

I have two C# IList Neden Kullanmalıyız ILists of the same type returned by NHibernate and have emerged the two IList into one, hence the need for sorting.

It doesn't affect the signature of the method, and is takım in stone at compile time. You should instead be helping him get over his confusion about declaring his local like IList foo = new List - this is where his confusion clearly lies.

Report this page