En Kuralları Of C# IList Neden Kullanmalıyız
Wiki Article
Note that, if your API is only going to be used in foreach loops, etc, then you might want to consider just exposing IEnumerable instead.
Arec BarrwinArec Barrwin 61.8k99 gold badges3030 silver badges2525 bronze badges 14 71 I have to disagree with your sardonic answer. I don't totally disagree with the sentiment of over-architecture being a real sıkıntı. However I think that especially in the case of collections that interfaces really shine.
Bu kent, istenmeyenleri azaltmak sinein Akismet kullanıyor. Yorum verilerinizin nasıl aksiyonlendiği hakkında daha lüks selen edinin.
Why does the Clausius inequality involve a single term/integral if we consider a body interacting with multiple heat sources/sinks?
The accepted answer by @DavidMills is quite good, but I think it birey be improved upon. For one, there is no need to define the ComparisonComparer class when the framework already includes a static method Comparer.Create(Comparison). This method emanet be used to create an IComparison on the fly.
IList on the other hand is an Interface. Basically, if you want to create your own custom List, say a list class called BookList, then you emanet use the Interface to give you basic methods and structure to your new class. IList is for when you want to create your own, special sub-class that implements List.
C# IList Kullanımı Don't you know in advance if your method needs a list that emanet take additional members; don't you specify that in the method signature? What exactly were you going to do if you were passed a read only list like int[]?
If you started with a concrete type and you decided to change to another one, even if it uses the same interface, you're going to break someone else's code unless you started off with an interface or abstract base type. Share Improve this answer Follow
Coming soon: Throughout 2024 we will be phasing out GitHub Issues kakım the feedback mechanism for content and replacing it with a new feedback system. For more information see: .
It is like this other question. The other question shares a lot of common ground, but is arguably not a true duplicate. In either case though, this is hamiş opinion-based. What may have happened is that the C# IList Nasıl Kullanılır closer might have just looked at this question's title, without reading the question itself. The body is objective.
In this case you could pass in any class which implements the IList interface. If you used List instead, only a List instance could be passed in.
When talking about return types, the more specific you C# IList Nedir are, the more flexible callers kişi be with it.
additional advantage is that your code is safe from C# IList Neden Kullanmalıyız any changes to concrete class as you are subscribing to only few of the methods of concrete class and those are the ones that are going to C# IList Nerelerde Kullanılıyor be there bey long kakım the concrete class inherits from the interface you are using.