Değil Hakkında Detaylar bilinen C# IList Kullanımı

The following example demonstrates the implementation of the IList interface to create a simple, fixed-size list. This code is part of a larger example for the IList interface.

IList is an interface so you gönül inherit another class and still implement IList while inheriting List prevents you to do so.

Say I have a function that returns IEnumerable, inside the function I may use a List for an internal backing store to generate my collection, but I only want callers to enumerate it's contents, derece add or remove. Accepting an interface kakım a parameter communicates a similar message "I need a collection of strings, don't worry though, I won't change it."

If you think that interfaces are useful only for building over-sized, grandiose architectures and have no place in small shops, then I hope that the person sitting across from you in the interview isn't me.

Your code is now broken, because int[] implements IList, but is of fixed size. The contract for ICollection (the base of IList) requires the code that uses it to check the IsReadOnly flag before attempting to add or remove items from the collection. The contract for List does not.

I would turn the question around a bit, instead of justifying why you should use the interface over the concrete implementation, try to justify why you would use the concrete implementation rather than the interface. If you sevimli't justify it, use the interface.

In case of using IList, the caller is always guareented things to work, and the implementer is free to change the underlying collection to any alternative concrete implementation of IList

Now I am returning IList for the simple fact that I will then add this to my domain sistem what saf a property like this:

the method, it can make a huge difference -- if they have C# IList Nedir an array and you're asking for a list, they have to change the array to a list or v.v. whenever calling the method, a total waste of time from both a programmer and performance POV.

List implements those nene methods (derece including extension methods), on top of that it katışıksız about 41 public C# IList Nerelerde Kullanılıyor methods, which weighs in your consideration of which one to use in your application.

IList.IsFixedSize bileğerinin mıhlı bir boyuta iye olup olmadığını IList belirten bir paha düzenır.

I leave this up to show that if you C# IList Nerelerde Kullanılıyor needed to do it (e.g. the off chance a third party library returned a List that you needed to convert for another 3rd party library), you C# IList Nedir dirilik do it this way.

When talking about return types, the more specific you are, the more flexible C# IList Nerelerde Kullanılıyor callers güç be with it.

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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Comments on “Değil Hakkında Detaylar bilinen C# IList Kullanımı”

Leave a Reply

Gravatar