C# ILIST NASıL KULLANıLıR HAKKıNDA GERçEKLER AçığA

C# IList Nasıl Kullanılır Hakkında Gerçekler Açığa

C# IList Nasıl Kullanılır Hakkında Gerçekler Açığa

Blog Article

The above is an IList itself bey this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but derece sure. Still, I emanet't figure out what the user would 100% need(that's where returning a concrete özgü an advantage over).

Maybe take it into a List of T rather than ArrayList, so that you get type safety and more options for how you implement the comparer.

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.

Eric LippertEric Lippert 656k182182 gold badges1.3k1.3k silver badges2.1k2.1k bronze badges 14 12 How do you know what the caller needs though. For instance I was switching one of my return types to a IList then I well I am probably just going to enumerate over them anyways lets just return an IEnumberable.

Kupkuru 4.6 (and it will likely be caught by the compiler). But there emanet be more insidious cases, such birli passing a C# array kakım a IList. I am hamiş sure everyone is aware arrays implement IList, which means support for Add should derece be assumed.

In some code this gönül be quite important and using concrete classes communicates your intent, your need for that specific class. An interface on the other hand says "I just need to call this takım of methods, no other contract implied."

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 C# IList Neden Kullanmalıyız infrastructure code around that must use reflection.

In fact, any time you are using reflection IList C# IList Nerelerde Kullanılıyor is more convenient than IList-of-T, since generics and reflection don't play nicely together. It gönül be done, but it is a pain. Unfortunately since C# IList Nerelerde Kullanılıyor IList-of-T doesn't derive from IList there are cases where this kişi fail - but it is a good 95% rule.

In VS2008, when I click on the service reference and select "Configure Service Reference", there is an option to C# IList Neden Kullanmalıyız choose how the client bile-serializes lists returned from the service.

tranmqtranmq 15.5k33 gold badges3232 silver badges2727 bronze badges 6 But in this case I gönül't bind my collection to DataGridView rather I have to expose the _list member in MyCollection.

kemiller2002kemiller2002 115k2828 gold badges198198 silver badges253253 bronze badges Add a comment  

Then I looked in my view(mvc) and found that I actually needed the count method birli I needed to use a for loop. So in my own application I under estimated what I actually needed how do you anticipate what someone else will need or hamiş need.

In particular, IList lets you use the indexer, and add/remove items; things that IEnumerable don't let you do.

additional advantage is that your code is safe from any changes to concrete class bey you are subscribing to only few of the methods of concrete class and those are the ones that are going to be there kakım long birli the concrete C# IList Neden Kullanmalıyız class inherits from the interface you are using.

Report this page