HAKKıNDA HERşEY C# ILIST NERELERDE KULLANıLıYOR

Hakkında herşey C# IList Nerelerde Kullanılıyor

Hakkında herşey C# IList Nerelerde Kullanılıyor

Blog Article

Else use List. You güç'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"

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

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.

Kişi a unique position be deduced if pieces are replaced by checkers (can see piece color but hamiş type)

IList is a interface and doesn't have any implementation, so the performance of IList depending the class it implements

In some code this hayat 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."

Bu kent, istenmeyenleri azaltmak yürekin Akismet kullanıyor. Yorum verilerinizin nasıl çalışmalendiği için daha çokça selen edinin.

OdedOded 496k101101 gold badges890890 silver badges1k1k bronze badges Add a comment  

Whether you return an Interface or a concrete type depends upon what you want 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 ability to make full use of the object against their ability to easily use a portion C# IList Nasıl Kullanılır of the objects functionality (and of course whether you WANT them to be making full use of the object).

The Cast function is just a reimplementation of the extension method that comes with 3.5 written as a olağan static method. It is quite ugly and verbose unfortunately.

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 C# IList Nerelerde Kullanılıyor interface without necessarily tying yourself to a specific implementation, especially if you have no control over who compiles against your code afterward.

rajeshrajesh 39133 silver badges22 bronze badges 1 8 Excellent, clear answer, which I marked bey helpful. However, I would add that for most developers, most of the time, the tiny C# IList Neden Kullanmalıyız difference in izlence size and performance is derece worth worrying about: if in doubt, just use a List.

This will C# IList Nedir help C# IList Nedir if you decide to change the implementation of your class later to use a different concrete class. In that case the users of your library won't need to update their code since the interface doesn't change.

It doesn't affect the signature of the method, and is set 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