AçıKLANAN C# ILIST NERELERDE KULLANıLıYOR HAKKıNDA 5 KOLAY GERçEKLER

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

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

Blog Article

driisdriis 163k4545 gold badges268268 silver badges343343 bronze badges 3 Sorry, but even now there are plenty of uses for library code to use IList (non-generic). Anyone who says otherwise hasn't suffered enough reflection / data-binding / etc ;)

Today, you almost always use IList, the primary reason for IList to still be around is for reasons of backwards compatibility.

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 sevimli lead to brittle code.

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.

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

so its safety for you and freedom to the coder who is writing concrete implementation to change or add more functionality to his concrete class.

 

In fact, any time you are using reflection IList is more convenient than IList-of-T, since generics and reflection don't play nicely together. It dirilik be done, but it is a pain. Unfortunately since IList-of-T doesn't derive from IList there are cases where this sevimli işleyen - but it is a good 95% rule.

The idea is that you hide the implementation details from the user, and instead provide them with a stable interface. This is to reduce dependency on details that might change in the future.

It really comes down to the kind of functionality you need. I'd suggest using the List class in most cases. IList is best for when you need to make a custom array that could have some very specific rules that you'd like to encapsulate within a collection so you don't repeat yourself, but still want .Kemiksiz to recognize it kakım a list.

If you're working within a single method (or even in a single class or assembly in some cases) and no one outside is going to see what C# IList Nerelerde Kullanılıyor you're doing, use the fullness of a List. But if you're interacting with outside code, like when you're returning a list from a method, then you only want to declare the interface without necessarily tying yourself to a specific implementation, especially if you have no control over who compiles against your code C# IList Kullanımı afterward.

Bu örnekte, Student isminde bir derslik ve StudentCollection isminde CollectionBase klasından türeyen özel bir koleksiyon dershaneı oluşturduk.

In particular, IList lets you use the indexer, and add/remove items; things that IEnumerable don't let you do.

Bu C# IList Nasıl Kullanılır şekilde, Dog klası IAnimal interface’inin sözleşmesine uymuş evet. Aynı şekilde, gayrı hayvan sınıfları da IAnimal interface’ini uygulayabilir. Örneğin, dundaki kodda bir Cat sınıfı tanımladım ve C# IList Nasıl Kullanılır IAnimal C# IList Nedir interface’ini uyguladım.

Report this page