EN IYI TARAFı C# ILIST KULLANıMı

En iyi Tarafı C# IList Kullanımı

En iyi Tarafı C# IList Kullanımı

Blog Article

Note that, if your API is only going to be used in foreach loops, etc, then you might want to consider just exposing IEnumerable instead.

Arec BarrwinArec Barrwin 61.8k99 gold badges3030 silver badges2525 bronze badges 14 71 I have to disagree with your sardonic answer. I don't totally disagree with the sentiment of over-architecture being a real mesele. However I think that especially in the case of collections that interfaces really shine.

You pass the interface so that no matter what concrete implementation of that interface you use, your code will support it.

Bearing this in mind, it makes most sense to pass types with the least number of external dependencies possible and to return the same. However, this could be different depending on the visibility of your methods and their signatures.

I tend to follow Jeffrey's advice for internal code, but for a public library, I would probably be more inclined to follow Eric's.

The Liskov Substitution Principle (simplified) states that a derived type should be able to be used in place of a base type, with no additional preconditions or postconditions.

Remove Silinmesini mergup değeri siler. Silinecek kırat liste içinde birden ziyade olması durumunda ilk değeri kaldırır. Bu metodu genellikle referans tipler ile değer çıkarmak sinein kullanılır. Fakat porte tipleri ile de kullanılabilir.

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.

And, if you don't even need everything in IList you kişi C# IList Nerelerde Kullanılıyor always use IEnumerable too. With çağdaş compilers and processors, I don't think there is really any speed difference, so this is more just a matter of style.

If you dirilik consider your method, determine that you probably won't C# IList Kullanımı be changing the return collection type, then it is probably safe to return a more exact type. If you C# IList Kullanımı aren't sure, or are afraid that if you change it in future you'll be breaking other people's code, then go more general.

I know that IList is the interface C# IList Nerelerde Kullanılıyor and List is the concrete type but I still don't know when to use each one. What I'm doing now is if I don't need the Sort or FindAll methods I use the interface. Am I right? Is there a better way to decide when to use the interface or the concrete type?

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

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

would C# IList Nasıl Kullanılır I run into problems with this? Since could they not pass in an array(that özgü a fixed size)? Would it be better maybe for a concrete List?

Report this page