En iyi Tarafı C# IList Kullanımı

driisdriis 163k4545 gold badges268268 silver badges343343 bronze badges 3 Sorry, but even now there are plenty of uses for library code to use IList (non-generic). Anyone who says otherwise hasn't suffered enough reflection / data-binding / etc ;)

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.

Bir dahaki sefere tefsir yapmış olduğumda kullanılmak üzere etapı, e-posta adresimi ve web kent adresimi bu tarayıcıya kaydet.

A List object allows you to create a list, add things to it, remove it, update it, index into it and etc. List is used whenever you just want a generic list where you specify object type in it and that's it.

ToList first? How about returning it? I don't understand what you mean by "method will survive" when using vars? I know it will be a bit more work but won't you just have to change that to the new type as well? So maybe IList to IList?

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 C# IList Kullanımı you would use the concrete implementation rather than the interface. If you güç't justify it, use the interface.

You are most often better of using the most general usable type, in this case the IList or even better the IEnumerable interface, so that you C# IList Nasıl Kullanılır can switch the implementation conveniently at a later time.

Matthew WatsonMatthew Watson 108k1111 gold badges170170 silver badges290290 bronze badges 2 2 This is trivially true for every interface. If you want to follow through with your argument, than you could argue to never use any interface at all, because some implementation of it might throw.

For collections C# IList Neden Kullanmalıyız you should aim to use IEnumerable where possible. This gives the most flexibility but is derece always suited.

Collaborate with us on GitHub The source for this content kişi be found on GitHub, where you hayat also create and review issues and pull requests. For more C# IList Nedir information, see our contributor guide.

Bayağıdaki şekilde Kisi adında oluşturduğumuz sınıfı oluşturduğumuz liste nesnesine ekleyelim.

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.

When talking about return types, the more specific you are, the more flexible callers kişi be with it.

ahead of time. Data-binding is a classic example here; a DataSource property usually checks for IList (and IListSource, typically) and then looks at the objects to see what C# IList Nedir properties are available. It yaşama't use generics in this case.

Leave a Reply

Your email address will not be published. Required fields are marked *