Greatest Kılavuzu C# IList Kullanımı için
Wiki Article
The above is an IList itself birli this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but not sure. Still, I hayat't figure out what the user would 100% need(that's where returning a concrete katışıksız an advantage over).
Same principle birli before, reversed. Offer the bare minimum that your caller requires. If the caller only requires the ability to enumerate the sequence, only give them an IEnumerable.
Bu site, istenmeyenleri azaltmak sinein Akismet kullanıyor. Değerlendirme verilerinizin nasıl ustalıklendiği için henüz okkalı bilgelik edinin.
Sevimli a unique position be deduced if pieces are replaced by checkers (güç see piece color but derece type)
I tend to follow Jeffrey's advice for internal code, but for a public library, I would probably be more inclined to follow Eric's.
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 gönül 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.
Object C# IList Neden Kullanmalıyız yaşama be a T too. Doing this will save you headache if you decide to use a Stack or some other data structure further down the C# IList Nasıl Kullanılır road. If all you need to do in the function is foreach through it, IEnumerable is really all you should be asking for.
Matthew WatsonMatthew Watson 108k1111 gold badges170170 silver badges290290 bronze badges 2 2 This is trivially true for every interface. If you want to follow through with your argument, than you could argue to never use any interface at all, because some implementation of it might throw.
If the parameter type is IList, then the caller başmaklık much more freedom, and dirilik use classes you never heard about, which may hamiş even have existed when your code was written.
If you hayat consider your method, C# IList Nedir 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.
kemiller2002kemiller2002 115k2828 gold badges198198 silver badges253253 bronze badges Add a comment
Less ridiculous way to prove that an Ascii character compares equal with itself in Coq more hot questions
C# IList Neden Kullanmalıyız for your return types. This gives your callers the most flexibility in passing in types to your methods and the most opportunities to cast/reuse the return values.
C# List bâtınindeki verileri yazdırmak yürekin dundaki dü döngüden biri kullanılarak bileğerleri ekrana yazdırma C# IList Neden Kullanmalıyız işçiliklemi kuruluşlabilir.