AçıKLANAN C# ILIST NERELERDE KULLANıLıYOR HAKKıNDA 5 KOLAY GERçEKLER

Açıklanan C# IList Nerelerde Kullanılıyor Hakkında 5 Kolay Gerçekler

Açıklanan C# IList Nerelerde Kullanılıyor Hakkında 5 Kolay Gerçekler

Blog Article

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 / data-binding / etc ;)

IList is an interface so you emanet inherit another class and still implement IList while inheriting List prevents you to do so.

So I came across an interesting sıkıntı today. We have a WCF web service that returns an IList. Hamiş really a big deal until I wanted to sort it.

All concepts are basically stated in most of the answers above regarding why use interface over concrete implementations.

Typically, a good approach is to use IList in your public facing API (when appropriate, and list semantics are needed), and then List internally to implement the API. This allows you to change to a different implementation of IList without breaking code that uses your class.

You güç have an instance of an interface, but you need to initialize it with a class that implements that interface such kakım:

Most app-level code (i.e. the everyday code that ou write for your application) should probably focus on the generic versions; however there is also a lot of infrastructure code around that must use reflection.

Then when you need "add" or "sort" then use Collection if need more then use List. So my hard rule would be: START always with IENumarable and if you need more then extend...

; being aware of the definition of the interface ie. all abstract methods that are there to be implemented by any class inheriting the interface. so if some one makes a huge class of C# IList Nasıl Kullanılır his own with several methods besides the ones he inherited from the interface for some addition functionality, and those are of no use to you, its better to use a reference to a subclass (in this case the interface) and assign the concrete class object to it.

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more C# IList Nedir information see: .

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 C# IList Nedir 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?

List communicates "I need to get and kaş the elements of this sequence in arbitrary order and I only accept lists; I do derece accept arrays."

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

would I run into problems with this? Since could they hamiş pass in an array(that has a C# IList Nerelerde Kullanılıyor fixed size)? Would it be better maybe for a concrete List?

Report this page