Greatest Kılavuzu C# IList Kullanımı için

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 yaşama't figure out what the user would 100% need(that's where returning a concrete özgü 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.

Interface’ler üzerine elan bir tomar bilim edinmek isterseniz, zirdaki kaynaklara ayn atabilirsiniz:

Eric LippertEric Lippert 656k182182 gold badges1.3k1.3k silver badges2.1k2.1k bronze badges 14 12 How do you know what the caller needs though. For instance I was switching one of my return types to a IList then I well I am probably just going to enumerate over them anyways lets just return an IEnumberable.

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

The speed difference is sufficiently great that in many cases it may be faster to copy a list to an array, sort the array, and copy the list back, than to try to have a sort routine process the list in place.

You may hamiş ever need that option, but it's an argument. I think it's the entire argument for returning the interface instead of the concrete type. It's worth mentioning, but in this case it saf a serious flaw.

From my reading I think I could have used IEnumberable instead of IList since I am just looping through stuff.

If you are exposing your class through a library that others will use, you generally want to expose it via interfaces rather than C# IList Nasıl Kullanılır concrete implementations.

Collaborate with us on GitHub The source for this content hayat be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.

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

Benefit of using an Interface is that you get to implement your functionality or better yet, the only functionality you require. So, if iteration/enumeration is required only, then there is no need for the C# IList Neden Kullanmalıyız Sort, Add methods.

If you're just enumerating over the values, you should be using IEnumerable. Every type of datatype C# IList Nerelerde Kullanılıyor that can hold more than one value implements IEnumerable (or should) and makes your method hugely flexible.

So I have been playing around with some of my methods on C# IList Nerelerde Kullanılıyor how to do this. I am still hamiş sure about the return type(if I should make it more concrete or an interface).

Leave a Reply

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