Açıklanan C# IList Nerelerde Kullanılıyor Hakkında 5 Kolay Gerçekler

Wiki Article

Arraylist: Hareketli boyutludur, eleman ekleme/silme fiillemleri daha kolaydır ve farklı muta türlerini saklayabilir.

1 @supercat: What could ISortableList offer that's not already in IList? Or, asked differently, why couldn't an IList be sorted in-place without re-adding the items by your imagined static method?

Also, it casts IList to IList which başmaklık the potential to be dangerous. In most cases that I have seen, List which implements IList is used behind the scenes to implement IList, but this is hamiş guaranteed and dirilik lead to brittle code.

David MillsDavid Mills 2,41511 gold badge2323 silver badges2525 bronze badges 6 2 The right approach really would have been to offer an ISortableList interface (with methods to sort a portion of the list using some particular comparer), have List implement it, and have a static method which could sort any IList by checking whether it implemented ISortableList and, if derece, copying it to an array, sorting that, clearing the IList, and re-adding the items.

Basically, I need to see some actual code examples of how using IList would have solved some sorun over just taking List into everything.

The Liskov Substitution Principle (simplified) states that a derived type should be able to be used in C# IList Nerelerde Kullanılıyor place of a base type, with no additional preconditions or postconditions.

Inside the method, you should use var, instead of IList or List. When your data source changes to come from a method instead, your onlySomeInts method will survive.

If your methods form part of an interface, the methods will need to be defined using types available to that interface.

If the parameter type is IList, then the caller katışıksız much more freedom, and dirilik use classes you never heard about, which may derece even have existed when your code was written.

Coming soon: Throughout 2024 we will be phasing out GitHub Issues kakım the feedback mechanism for content and replacing it with a new feedback system. For more information see: .

However, this makes the method more fragile, as any change to the returned object type may break the C# IList Kullanımı calling code. In practice though, that generally isn't a major mesele.

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

This will help C# IList Nedir if you decide to change the implementation of your class later to use a different concrete class. In C# IList Kullanımı that case the users of your library won't need to update their code since the interface doesn't change.

would I run into problems with this? Since could they derece pass in an array(that has a C# IList Nedir fixed size)? Would it be better maybe for a concrete List?

Report this wiki page