DEğIL HAKKıNDA GERçEKLER BILINEN C# ILIST NERELERDE KULLANıLıYOR

Değil Hakkında Gerçekler bilinen C# IList Nerelerde Kullanılıyor

Değil Hakkında Gerçekler bilinen C# IList Nerelerde Kullanılıyor

Blog Article

I toyed with writing an extension method, also with inheriting from IList and implementing my own Sort() method as well kakım casting to a List but none of these seemed overly elegant.

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.

The less popular answer is programmers like to pretend their software is going to be re-used the world over, when infact the majority of projects will be maintained by a small amount of people and however nice interface-related soundbites are, you're deluding yourself.

The following example demonstrates the implementation of the IList interface to create a simple, fixed-size list.

The accepted answer by @DavidMills is quite good, but I think it kişi 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 can be used to create an IComparison on the fly.

Convert your IList into List or some other generic collection and then you sevimli easily query/sort it using System.Linq namespace (it will supply bunch of extension methods)

 

Now I am returning IList for the simple fact that I will C# IList Nasıl Kullanılır then add this to my domain prototip what katışıksız a property like this:

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

If you sevimli consider your method, determine that you probably won't be changing the return collection type, then it is probably safe to return a more 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.

By asking for more than you need, you (1) make the caller do unnecessary work to satisfy your unnecessary demands, and (2) communicate falsehoods to the reader. Ask only for what you're going to use. That way if the caller başmaklık a sequence, they don't need to call ToList on it to satisfy your demand.

Brad LeachBrad Leach 17k1818 gold badges7373 silver badges8888 bronze badges 1 3 It will create a new enumerable, which may not be desirable in some scenarios. You cannot sort an IList in-place through the interface except by using ArrayList.Adapter method in my knowledge.

When talking about return types, the more specific you are, the more flexible callers hayat be C# IList Neden Kullanmalıyız with it.

additional advantage is that your code is safe from any changes to concrete class bey you are subscribing to only few of the methods of concrete C# IList Nasıl Kullanılır class and those are the ones that are going to be there birli long as the C# IList Kullanımı concrete C# IList Neden Kullanmalıyız class inherits from the interface you are using.

Report this page