EN IYI TARAFı C# ILIST KULLANıMı

En iyi Tarafı C# IList Kullanımı

En iyi Tarafı C# IList Kullanımı

Blog Article

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

Found this thread while I was looking for a solution to the exact mesele described in the original post. None of the answers met my situation entirely, however. Brody's answer was pretty close. Here is my situation and solution I found to it.

Important Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Your functions above only care about being able to iterate over a list. Ideally they shouldn't need to know who implements that list or how they implement it.

In this specific case since you're essentially talking about a language construct, not a custom one it generally won't matter, but say for example that you found List didn't support something you needed.

GitHub'da bizimle ortaklaşa iş örgün Bu dâhilğin kaynağı GitHub'da bulunabilir; burada başkaca sorunları ve çekme isteklerini oluşturup gözden geçirebilirsiniz. Elan fazla fen C# IList Kullanımı kucakin yardımda kâin kılavuzumuzu inceleyin.

 

Matthew WatsonMatthew Watson 108k1111 gold badges170170 silver badges290290 bronze badges 2 2 This is trivially true for every interface. If you want to C# IList Nasıl Kullanılır 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 özgü much more freedom, and C# IList Neden Kullanmalıyız güç use classes you never heard about, which may hamiş even have existed when your code was written.

If you code your own class implementing the IList interface, make sure you also implement the non-generic IList interface, or the code will eden with a class cast exception.

By asking for more than you need, you (1) make the caller do unnecessary work to satisfy C# IList Kullanımı your unnecessary demands, and (2) communicate falsehoods to the reader. Ask only for what you're going to use. That way if the caller has a sequence, they don't need to call ToList on it to satisfy your demand.

rajeshrajesh 39133 silver badges22 bronze badges 1 8 Excellent, clear answer, which I marked birli helpful. However, I would add that for most developers, most of the time, the tiny difference in yetişek size and performance is derece worth worrying about: if in doubt, just use a List.

You accept an Interface birli a parameter for a method because that allows the caller to submit different concrete types birli arguments. Given your example method LogAllChecked, the parameter someClasses could be C# IList Nasıl Kullanılır of various types, and for the person writing

If you had used IList in the rest of the app you could extend List with your own custom class and still be able to pass that around without refactoring.

Report this page