DüşüNCELER HAKKıNDA BILMEK C# ILIST NEDIR

Düşünceler Hakkında Bilmek C# IList Nedir

Düşünceler Hakkında Bilmek C# IList Nedir

Blog Article

Else use List. You yaşama't really argue "oh but I KNOW that I will always pass in a List here", then you should take a List hamiş an IList, else you are breaking Liskov substitution principle: "if S is a subtype of T, then objects of type T may be replaced with objects of type S"

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.

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

That way you take advantage if you hayat, 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.

In some code this kişi 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 set of methods, no other contract implied."

Most app-level code (i.e. the everyday code that ou write for your application) should probably focus on the generic versions; however there is also a C# IList Nasıl Kullanılır lot of infrastructure code around that must use reflection.

In fact, any time you are using reflection IList is more C# IList Kullanımı convenient than IList-of-T, since generics and reflection don't play nicely together. It can be done, but it is C# IList Nedir a pain. Unfortunately since IList-of-T doesn't derive from IList there are cases where this kişi eden - but it is a good 95% rule.

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 you require a particular access performance characteristic.

Want to improve this question? Update the question so it kişi be answered with facts and citations by editing this post.

If you're working within a single method (or even in a single class or assembly in some cases) and no one outside is going to see what you're doing, use the fullness of a List. But if you're interacting with outside code, like when you're returning a list from a method, then you only want to declare the interface without necessarily tying yourself to a specific implementation, especially if you have no control over who compiles against your code afterward.

You might want to have an IOrderRepository that defines a collection of orders in either a IList or ICollection. You could then have different kinds of implementations to provide a list of orders birli long kakım they conform to "rules" defined by your IList or ICollection.

In collections of contiguous elements, such bey lists, the elements that follow the insertion point move down to accommodate the C# IList Nasıl Kullanılır new element.

There is a complication though that dynamic C# IList Nedir gönül't see explicit implementations, so something kişi implement IList and IList-of-T and yet still be completely unusable from dynamic.

Report this page