BENIM C# ILIST NEDEN KULLANMALıYıZ BAşLARKEN ÇALışMAK

Benim C# IList Neden Kullanmalıyız Başlarken Çalışmak

Benim C# IList Neden Kullanmalıyız Başlarken Çalışmak

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 not sure. Still, I yaşama't figure out what the user would 100% need(that's where returning a concrete özgü an advantage over).

IList is an interface so you dirilik inherit another class and still implement IList while inheriting List prevents you to do so.

lomaxxlomaxx 115k5858 gold badges146146 silver badges180180 bronze badges 1 Why would you return an IList in the first place? From a WCF service?

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 not, 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 sıkıntı over just taking List into everything.

List is a specific implementation of IList, which is a container that güç be addressed the same way kakım a linear array T[] using an integer index. When you specify IList kakım the type of the method's argument, you only specify that you need certain capabilities of the container. For example, the interface specification does hamiş enforce a specific veri structure to C# IList Nedir be used.

Object sevimli be a T too. Doing this will save you headache if you decide to use a Stack or some other veri structure further down the road. If all you need to do in the function is foreach through it, IEnumerable is really all you C# IList Nasıl Kullanılır should be asking for.

Now I am returning IList for the simple fact that I will then add this to my domain prototip what başmaklık a property like this:

The C# IList Nasıl Kullanılır idea is that you hide the implementation details from the user, and instead provide them with a stable interface. This is to reduce dependency on details that might C# IList Nasıl Kullanılır change in the future.

C# List içindeki verileri yazdırmak midein adidaki iki döngüden biri kullanılarak değerleri ekrana yazdırma nöbetlemi konstrüksiyonlabilir.

It is like this other question. The other question shares a lot of common ground, but is arguably hamiş a true duplicate. In either case though, this is hamiş opinion-based. What may have happened is that the closer might have just looked at this question's title, without reading the question itself. The body is objective.

Returning C# IList Kullanımı a read-only interface such bey IEnumerable is often the way to go for data-retrieval methods. Your consumer sevimli project it into a richer type bey-needed.

If you use the concrete type all callers need to be updated. If exposed kakım IList the caller doesn't have to be changed.

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.

Report this page