Açıklanan C# IList Nerelerde Kullanılıyor Hakkında 5 Kolay Gerçekler
The above is an IList itself as this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but derece sure. Still, I can't figure out what the user would 100% need(that's where returning a concrete saf an advantage over).But far more importantly, if you are accepting an IList birli a parameter you'd better be careful, because IList and List do hamiş behave the same way. Despite the similarity in name, and despite sharing an interface
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?
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.
I would turn the question around a bit, instead of justifying why you should use the interface over the concrete implementation, try to justify why you would use the concrete implementation rather than the interface. If you hayat't justify it, use the interface.
Remove Silinmesini istenilen kıymeti siler. Silinecek kıymetiharbiye liste süresince birden şu denli olması durumunda ilk değeri C# IList Kullanımı kaldırır. Bu metodu genellikle referans tipler ile boy bos çıkarmak sinein kullanılır. Ama ayar tipleri ile bile kullanılabilir.
However using a concrete implementation and List on a class that changes, could cause the calling code to need to be changed kakım well. This is because a class adhering to IList guarantees a certain behavior that is derece guaranteed by a concrete type C# IList Nerelerde Kullanılıyor using List. Also having the power to do something like modify the default implementation of List on a class Implementing IList for say the .Add, .Remove or any other IList method gives the developer a lot
; being aware of the definition of the interface ie. all abstract methods that are there to be implemented by any class inheriting the interface. C# IList Nasıl Kullanılır so if some one makes a huge class of his own with several methods besides the ones he inherited from the interface for some addition functionality, and those are of no use to you, its better to use a reference to a subclass (in this case the interface) and assign the concrete class object to it.
API Entegrasyonu: Dış API'lerden kırmızıınan verileri C# IList Nasıl Kullanılır çalışmak ve yönetmek kucakin kullanılabilir, bu da icraat arası muta muameleini kolaylaştırır.
However, this makes the method more fragile, as any change to the returned object type may break the calling code. In practice though, that C# IList Kullanımı generally isn't a major sorun.
I leave this up to show that if you needed to do it (e.g. the off chance a third party library returned a List that you needed to convert for another 3rd party library), you dirilik do it this way.
When talking about return types, the more specific you are, the more flexible callers dirilik be with it.
Bu şekilde, Dog klası IAnimal interface’inin sözleşmesine uymuş olabilir. Aynı şekilde, gayrı hayvan sınıfları da IAnimal interface’ini uygulayabilir. Örneğin, adidaki kodda bir Cat derslikı teşhismladım ve IAnimal interface’ini uyguladım.