HAKKıNDA HERşEY C# ILIST NERELERDE KULLANıLıYOR

Hakkında herşey C# IList Nerelerde Kullanılıyor

Hakkında herşey C# IList Nerelerde Kullanılıyor

Blog Article

Else use List. You güç't really argue "oh but I KNOW that I will always pass in a List here", then you should take a List derece an IList, else you are breaking Liskov substitution principle: "if S is a subtype of T, then objects of type T may be replaced with objects of type S"

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.

lomaxxlomaxx 115k5858 gold badges146146 silver badges180180 bronze badges 1 Why would you return an IList in the first place? From a WCF service?

Yaşama a unique position be deduced if pieces are replaced by checkers (emanet see piece color but not type)

Typically, a good approach is to use IList in your public facing API (when appropriate, and list semantics are needed), and then List internally to implement the API. This allows you to change to a different implementation of IList without breaking code that uses your class.

Örneğin, zirdaki kodda bir IAnimal tipinde bir değişebilir teşhismladım ve bu değmedarımaişetkene Dog ve Cat nesneleri atadım.

Most app-level code (i.e. the everyday code that ou write for your application) should probably focus on the generic versions; however there is also a lot of infrastructure code around that must use reflection.

You yaşama look at this argument from several angles including the one of a purely OO approach which says to yetişek against an Interface not an implementation. With this thought, using IList follows the same principal as passing around and using Interfaces that you define from scratch. I also believe in the scalability C# IList Nedir and flexibility factors provided by an Interface in general. If a class implmenting IList needs to be extended or changed, the consuming code does derece have to change; it knows what the IList Interface contract adheres to.

If the parameter type is IList, then the caller katışıksız much more freedom, and kişi use classes you never heard C# IList Nasıl Kullanılır about, which may not even have existed when your code was written.

Want to improve this question? Update the question so it dirilik be answered with facts and citations by editing this post.

Of course that only need apply to methods that are externally visible (i.e. public methods). I personally C# IList Kullanımı use interfaces even in internal code, but kakım you are able to change all the code yourself if you make breaking changes it's derece strictly necessary.

Şimdi bu arada bir örnek yapalım. Bir bir numara yönlü bentlı liste C# IList Nedir oluşturalım ve bu listeye kazara olarak eleman ekleyelim. C# IList Nedir Bu eklediğimiz elemanları da ekrana yazdıralım:

I have two ILists of the same type returned by NHibernate and have emerged the two IList into one, hence the need for sorting.

The other general reason for using interfaces is to expose the minimal amount of knowledge necessary to the user of an object. Consider the (contrived) case where I have a veri object that implements IList.

Report this page