En iyi Tarafı C# IList Nedir

It's always best to use the lowest base type possible. This gives the implementer of your interface, or consumer of your method, the opportunity to use whatever they like behind the scenes.

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 problem. However I think that especially in the case of collections that interfaces really shine.

If someone passes you an Array or a List, your code will work fine if you check the flag every time and have a fallback... But really; who does that?

That way you take advantage if you can, while still allowing the client flexibility in what they pass in.

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

I would turn the question around a bit, instead of justifying why you should use the interface over the concrete implementation, try to justify why you would use the concrete implementation rather than the interface. If you kişi't justify it, use the interface.

The cost to do this is minimal, why derece save yourself the headache later? It's what the interface principle is all about.

You can look at this argument from several angles including the one of a purely OO approach which says to yetişek against an Interface derece an C# IList Neden Kullanmalıyız implementation. With this thought, using IList follows the same principal as passing around and using Interfaces that you define from scratch. I also believe in the scalability and C# IList Nerelerde Kullanılıyor flexibility factors provided by an Interface in general. If a class implmenting IList needs to be extended or changed, the consuming code does hamiş have to change; C# IList Nerelerde Kullanılıyor it knows what the IList Interface contract adheres to.

In VS2008, when I click on the service reference and select "Configure Service Reference", there is an option to C# IList Neden Kullanmalıyız choose how the client de-serializes lists returned from the service.

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

SQL Mükerrer Kayıtlar Tedarik etmek ve Silmek, hatm ile sql terbiye setime devam ediyorum. Bu yazgımda tablolalarımızdaki mükerrer kayıtları nasıl bulabileceğimizi ve silebileceğimizi göstereceğim. SQL Mükerrer…

I leave this up to show that if you needed to do it (e.g. the off chance a third party library returned a List that you needed to convert for another 3rd party library), you birey do it this way.

When talking about return types, the more specific you are, the more flexible callers hayat be with it.

Have children's car seats hamiş been proven to be more effective than seat belts alone for kids C# IList Nedir older than 24 months?

Leave a Reply

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