Bir İnceleme C# IList Neden Kullanmalıyız

Wiki Article

şu demek oluyor ki IEnumerable yapısında filtreleme ustalıklemleri memory bile yapılırken, IQueryable da veritabanından direk filtrelenmiş verileri elde ederiz.

But far more importantly, if you are accepting an IList birli a parameter you'd better be careful, because IList and List do derece behave the same way. Despite the similarity in name, and despite sharing an interface

Interface’ler hakkında henüz ziyade bilgi yapmak isterseniz, bayağıdaki kaynaklara bölüm atabilirsiniz:

It's more nuanced than that. If you are returning an IList bey part of the public interface to your library, you leave yourself interesting options to perhaps make a custom list in the future.

The preceeding line of code will work, but you will only have the members of IList available to you instead of the full takım from whatever class you initialize.

IList on the other hand is an Interface. Basically, if you want to create your own custom List, say a list class called BookList, then you yaşama use the Interface to give you basic methods and structure to your new class. IList is for when you want to create your own, special sub-class that implements List.

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

Now I am returning IList for the simple fact that I will then C# IList Neden Kullanmalıyız add this to my domain model what has a property like this:

Bir dahaki sefere yorum yaptığımda kullanılmak üzere etapı, e-posta adresimi ve web şehir adresimi bu tarayıcıevet kaydet.

Then later if you decide to convert the actual C# IList Nasıl Kullanılır data store from a List to a Dictionary and expose the dictionary keys bey the actual value for the property (I have had to do exactly this before). C# IList Nasıl Kullanılır Then consumers who have come to expect that their changes will be reflected inside of your class will C# IList Nasıl Kullanılır no longer have that capability. That's a big sorun! If you expose the List as an IEnumerable you sevimli comfortably predict that your collection is not being modified externally. That is one of the powers of exposing List bey any of the above interfaces.

On the other hand, when returning an object out of a function, you want to give the user the richest possible set of operations without them having to cast C# IList Nasıl Kullanılır around. So in that case, if it's a List internally, return a copy bey a List.

List communicates "I need to get and takım the elements of this sequence in arbitrary order and I only accept lists; I do not accept arrays."

You accept an Interface birli a parameter for a method because that allows the caller to submit different concrete types kakım arguments. Given your example method LogAllChecked, the parameter someClasses could be of various types, and for the person writing

So I have been playing around with some of my methods on how to do this. I am still not sure about the return type(if I should make it more concrete or an interface).

Report this wiki page