C# IList Nasıl Kullanılır Herkes İçin Eğlenceli Olabilir

Wiki Article

The above is an IList itself as this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but not sure. Still, I birey't figure out what the user would 100% need(that's where returning a concrete has an advantage over).

But far more importantly, if you are accepting an IList as 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

Using IList instead of List makes writing unit tests significantly easier. It allows you to use a 'Mocking' library to pass and return veri.

Sevimli a unique position be deduced if pieces are replaced by checkers (emanet see piece color but derece type)

NET 4.6 (and it will likely be caught by the compiler). But there yaşama be more insidious cases, such as passing a C# array as a IList. I am not sure everyone is aware arrays implement IList, which means support for Add should not be assumed.

Architecture Astronauts. The C# IList Nerelerde Kullanılıyor chances you will ever write your own IList that adds anything to the ones already in the .Kemiksiz C# IList Nedir framework are so remote that it's theoretical jelly tots reserved for "best practices".

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.

 

For collections you should aim to use IEnumerable where possible. This gives the most flexibility but is derece always suited.

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

kemiller2002kemiller2002 115k2828 gold badges198198 silver badges253253 bronze badges Add a comment  

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

C# IList Neden Kullanmalıyız When talking about return types, the more specific you are, the more flexible callers kişi be with it.

Have children's car seats not been proven C# IList Nerelerde Kullanılıyor to be more effective than seat belts alone for kids older than 24 months?

Report this wiki page