Hakkında herşey C# IList Nasıl Kullanılır

Do the decoupling capacitors act as capacitive load to the opamp which is used to make a virtual gorund?

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

Bir dahaki sefere yorum yaptığımda kullanılmak üzere hamleı, e-posta adresimi ve web kent adresimi bu tarayıcıevet kaydet.

That way you take advantage if you birey, while still allowing the client flexibility in what they pass in.

Use whatever you want. It's your method. You're the only one who gets to see the internal implementation details of the method.

I would turn the question around a bit, instead of justifying why you should use the interface over the concrete implementation, try to justify why you would use the concrete implementation rather than the interface. If you güç't justify it, use the interface.

+1 for all of us who hate it when a small app is loaded with interfaces and clicking on "find definition" takes us somewhere OTHER than the source of the sorun... Dirilik I borrow the phrase "Architecture Astronauts"? I emanet see it will come in handy.

You sevimli look at this argument from several angles including the one of a purely OO approach which says to program against an Interface hamiş an implementation. With this thought, using IList follows the same principal bey passing around and using Interfaces that you define from scratch. I also believe in the scalability and flexibility factors provided by an Interface in general. If a class implmenting IList needs to be extended or changed, the consuming code does hamiş have to change; it knows what the C# IList Nasıl Kullanılır IList Interface contract adheres to.

This example also tells you that there may be situations when you need to specify the implementation, not the interface, in the argument list: In this example, whenever C# IList Neden Kullanmalıyız you require a particular access performance characteristic.

If you can consider your method, determine that you probably won't be changing C# IList Neden Kullanmalıyız the return collection type, then it is probably safe to return a more C# IList Nedir 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.

I know that IList is the interface and C# IList Nerelerde Kullanılıyor 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?

rajeshrajesh 39133 silver badges22 bronze badges 1 8 Excellent, clear answer, which I marked kakım helpful. However, I would add that for most developers, most of the time, the tiny difference in program size and performance is not worth worrying about: if in doubt, just use a List.

I have two ILists of the same type returned by NHibernate and have emerged the two IList into one, hence the need for sorting.

For instance, if you return an IEnumerable, then you are limiting them to iterating -- they hayat't add or remove items from your object, they kişi only act against the objects. If you need to expose a collection outside of a class, but don't want to let the caller change the collection, this is one way of doing it. On the other hand, if you are returning an empty collection that you expect/want them to populate, then an IEnumerable is unsuitable.

Leave a Reply

Your email address will not be published. Required fields are marked *