C# ILIST KULLANıMı ILE ILGILI DETAYLı NOTLAR

C# IList Kullanımı Ile ilgili detaylı notlar

C# IList Kullanımı Ile ilgili detaylı notlar

Blog Article

I toyed with writing an extension method, also with inheriting from IList and implementing my own Sort() method kakım well kakım casting to a List but none of these seemed overly elegant.

Maybe take it into a List of T rather than ArrayList, so that you get type safety and more options for how you implement the comparer.

If someone passes you an Array or a List, your code will work fine if you check the flag every time and have a fallback... But really; who does that?

It's more nuanced than that. If you are returning an IList kakım part of the public interface to your library, you leave yourself interesting options to perhaps make a custom list in the future.

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.

In some code this kişi be quite important and using concrete classes communicates your intent, your need for that specific class. An interface on the other hand says "I just need to call this grup of methods, no other contract implied."

The class name List may be changed in next .kemiksiz framework but the interface is never going to change bey interface is contract.

If you specify your methods to return an interface that means you are free to change the exact implementation later on without the consuming method ever knowing.

For example, let's say you have a Person class and a Group class. A Group instance başmaklık many people, so a List here would make sense. When I declare the list object in Group I will C# IList Kullanımı use an IList and instantiate it bey a List.

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 C# IList Neden Kullanmalıyız a class cast exception.

Bir sonraki elementin varlığını sınayan MoveNext ve makbul elementi veren GetCurrent metodlarına sahiptir.

Then I looked in my view(mvc) and found that I actually needed the count method bey I needed to use a for loop. So in my own application I under estimated what I actually needed how do C# IList Nasıl Kullanılır you anticipate what someone else will need or not need.

Unless you have a very compelling reason to do so, your best bet will be to inherit from System.Collections.ObjectModel.Collection since it has everything you need.

It doesn't affect the signature of the method, and is takım in stone at C# IList Kullanımı compile time. C# IList Nedir You should instead be helping him get over his confusion about declaring his local like IList foo = new List - this is where his confusion clearly lies.

Report this page