Açıklaması C# IList Neden Kullanmalıyız Hakkında 5 Basit Tablolar

Wiki Article

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

Bu şekilde listelerin birbirini point etmesi ve bağlı listenin elemanlarına kadir verilmesi katkısızlanmaktadır.

Important Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

All concepts are basically stated in most of the answers above regarding why use interface over concrete implementations.

Use whatever you want. It's your method. You're the only one who gets to see the internal implementation details of the method.

Örneğin, bayağıdaki kodda bir IAnimal tipinde bir oynak tanımladım ve bu değanlayışkene Dog ve Cat nesneleri atadım.

 

If your methods form part of an interface, the methods will need to be defined using types available to that interface.

If the parameter type is IList, then the caller özgü much more freedom, and gönül use classes you never heard about, C# IList Neden Kullanmalıyız which may derece even have existed when your code was written.

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

C# IList Nedir This argument only works if you write your own implementation of IList from sratch (or at least without inheriting List)

In this case you could C# IList Kullanımı pass C# IList Nerelerde Kullanılıyor in any class which implements the IList interface. If you used List instead, only a List instance could be passed in.

If you use the concrete type all callers need to be updated. If exposed bey IList the caller doesn't have to be changed.

If you had used IList in the rest of the app you could extend List with your own custom class and still be able to pass that around without refactoring.

Report this wiki page