5 BASIT TEKNIKLERI IçIN C# ILIST KULLANıMı

5 Basit Teknikleri için C# IList Kullanımı

5 Basit Teknikleri için C# IList Kullanımı

Blog Article

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.

From this it follows that your method implementation hayat 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. Birli I presented a slightly different syntax to the other answers, I will leave my answer - however, the other answers presented are equally valid.

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

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

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

In case of using IList, the caller is always guareented things to work, and the implementer is free to change the underlying collection to any alternative concrete implementation of IList

OdedOded 496k101101 gold badges890890 C# IList Nasıl Kullanılır silver badges1k1k bronze badges Add a comment  

For example, let's say you have a Person class and a Group class. A C# IList Nerelerde Kullanılıyor Group instance has many people, so a List here would make sense. When I declare the list object in Group I will use an IList and instantiate it kakım a List.

If you gönül consider your method, C# IList Nerelerde Kullanılıyor 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.

Of course that only need apply to methods that are externally visible (i.e. public methods). I personally use interfaces even in internal code, but as you are able to change all the code yourself if you make breaking changes it's not strictly necessary.

Returning a read-only interface such birli IEnumerable is often the way to go for data-retrieval methods. Your consumer gönül project it into a richer type as-needed.

When talking about return C# IList Nedir types, the more specific you are, the more flexible callers dirilik be with it.

additional C# IList Nasıl Kullanılır 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 class and those are the ones that are going to be there bey long as the concrete class inherits from the interface you are using.

Report this page