It's always best to use the lowest base type possible. This gives the implementer of your interface, or consumer of your method, the opportunity to use whatever they like behind the scenes.
Performans Optimizasyonu: IList, data erişimini optimize ederek uygulamanın başarımını fazlalıkrabilir ve akıl yönetimini iyileştirebilir.
The less popular answer is programmers like to pretend their software is going to be re-used the world over, when infact the majority of projects will be maintained by a small amount of people and however nice interface-related soundbites are, you're deluding yourself.
That way you take advantage if you gönül, while still allowing the client flexibility in what they pass in.
C# Mod Alıntı İşlemi , yazımız ile c sharp eğitimimize devam ediyoruz. Bu dersimizde Mod transfer kısaca bölme davranışleminden artan bulma davranışlemini göreceğiz. Bu bap…
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.
I thought I'd never need to change from a List but had to later change to use a custom list library for the extra functionality it provided. Because I'd only returned an IList none of the people that used the library had to change their code.
Now I am returning C# IList Nasıl Kullanılır IList for the simple fact that I will then add this to my domain biçim what has a property like this:
If you are exposing your class through a library that others will use, you generally want to expose it via interfaces rather than concrete implementations.
API Entegrasyonu: Dış API'lerden hileınan verileri öğretmek ve yönetmek için kullanılabilir, bu da icraat arası data C# IList Nedir aksataini kolaylaştırır.
I know that IList is the interface 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 C# IList Neden Kullanmalıyız interface. Am I right? Is there a better way to decide when to use the interface or the C# IList Nedir concrete type?
In this case you could pass in any class which implements the IList interface. If you used List instead, only a List instance could be passed in.
I have two ILists of the same C# IList Nedir type returned by NHibernate and have emerged the two IList into one, hence the need for sorting.
For instance, if you return an IEnumerable, then you are limiting them to iterating -- they gönül't add or remove items from your object, they hayat only act against the objects. If you need to expose a collection outside of a class, but don't want to let the caller change the collection, this is one way of doing it. On the other hand, if you are returning an empty collection that you expect/want them to populate, then an IEnumerable is unsuitable.