C# IList Kullanımı Günlükler

driisdriis 163k4545 gold badges268268 silver badges343343 bronze badges 3 Sorry, but even now there are plenty of uses for library code to use IList (non-generic). Anyone who says otherwise hasn't suffered enough reflection / veri-binding / etc ;)

From this it follows that your method implementation hayat represent its local variables however you wish. The implementation details are derece exposed. Leaving you free to change your code to something better without affecting the people calling your code.

You pass the interface so that no matter what concrete implementation of that interface you use, your code will support it.

It's more nuanced than that. If you are returning an IList bey part of the public interface to your library, you leave yourself interesting options to perhaps make a custom list in the future.

In addition to the older code that doesn't know about generics, there are also a lot of cases where you know you have a list

Architecture Astronauts. The chances you will ever write your own IList that adds anything to the ones already in the .Safi framework are so remote that it's theoretical jelly tots reserved for "best practices".

The class name List may be changed in next .safi framework but the interface is never going to change bey interface is contract.

Ask those people what they'd like the methods to return. Your question is fundamentally "how do I know what software to write?" You know by getting to know what problems your customer katışıksız to solve, and writing code that solves their problems.

Whether you return an Interface or a concrete type depends upon what you want C# IList Nedir to let your callers do with the object you created -- this is an API design decision, and there's no hard and fast rule. You have to weigh their C# IList Nerelerde Kullanılıyor ability to make full use of the object against their ability to easily use a portion of the objects functionality (and of course whether you WANT them to be making full use of the object).

You would because defining an IList or an ICollection would open up for other C# IList Kullanımı implementations of your interfaces.

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?

Benefit of using an Interface is that you get to implement your functionality or better yet, the only functionality you require. So, if iteration/enumeration is required only, then there is no need for the Sort, Add methods.

for your return types. This C# IList Nasıl Kullanılır gives your callers the most flexibility in passing in types to your methods and the most opportunities to cast/reuse the return values.

additional advantage is that your code is safe from any changes to concrete class kakım you are subscribing to only few of the methods of concrete class and those are the ones that are going to be there birli long kakım the concrete class inherits from the interface you C# IList Nedir are using.

Leave a Reply

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