C# IList Nerelerde Kullanılıyor No Further Mystery

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

Lütfen zirdaki kutuya şikayetinizin bilgilerinı edebiyat. Şikayetinizi değerlendirildikten sonrasında size olgun vereceğiz.

You pass the interface so that no matter what concrete implementation of that interface you use, your code will support it.

If you think that interfaces are useful only for building over-sized, grandiose architectures and have no place in small shops, then I hope that the person sitting across from you in the interview isn't me.

Basically, I need to see some actual code examples of how using IList would have solved some mesele over just taking List into everything.

This level of abstraction goes the other direction when it belongs to method parameters. When you pass your list to a method that accepts IEnumerable you yaşama be sure that your list is hamiş going to be modified. When you are the person implementing the method and you say you accept an IEnumerable because all you need to do is iterate through that list.

I thought I'd never need to change from a List but had to later change to use a custom list library for the extra functionality it provided. Because I'd only returned an IList none of the people that used the library had to change their code.

Now I am returning IList for the simple fact that I will then add this to my domain sistem what özgü a property like this:

The idea is that you hide the implementation details from the user, and instead provide them with a stable interface. This is to reduce dependency on details that might change in the future.

If you can consider your method, determine that you probably won't be changing the return collection C# IList Nasıl Kullanılır 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.

However, this makes the method more fragile, bey any change to the returned object type may break the calling code. In practice though, that generally C# IList Nasıl Kullanılır isn't a major sorun.

Şimdi bu arada bir örnek yapalım. Bir uslu yönlü ilgilı liste oluşturalım ve bu listeye rastgele olarak eleman ekleyelim. Bu eklediğimiz elemanları da C# IList Nedir ekrana yazdıralım:

And, if you used a generic implementation, you would only be able to use a method that works for any object only with objects C# IList Nasıl Kullanılır of a specific type.

The other general reason for using interfaces is to expose the minimum amount of C# IList Kullanımı knowledge necessary to the user of an object. Consider the (contrived) case where I have a data object that implements IList.

Leave a Reply

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