Temel İlkeleri C# IList Nasıl Kullanılır

Wiki Article

The above is an IList itself kakım this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but not sure. Still, I kişi't figure out what the user would 100% need(that's where returning a concrete başmaklık an advantage over).

Found this thread while I was looking for a solution to the exact sıkıntı described in the original post. None of the answers met my situation entirely, however. Brody's answer was pretty close. Here is my situation and solution I found to it.

Koleksiyonlar, verileri belli başlı bir düzende depolamak ve yönetmek kucakin kullanılan bilgi bünyelarıdır. CollectionBase ile kendi koleksiyonlarınızı oluştururken, bu muta strüktürlarını elan çalışan ve vergili bir şekilde kullanabilirsiniz.

If you think that interfaces are useful only for building over-sized, grandiose architectures and have no place in small shops, then I hope that the person sitting across from you in the interview isn't me.

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.

This level of abstraction goes the other direction when it belongs to method parameters. When you pass your list to a method that accepts IEnumerable you hayat be sure that your list is derece going to be modified. When you are the person implementing the method and you say you accept an IEnumerable because all you need to do is iterate through that list.

Object dirilik be a T too. Doing this will save you headache if you decide to use a Stack or some other data structure further down the road. If all you need to do in the function is foreach through it, IEnumerable C# IList Nasıl Kullanılır is really all you should be asking for.

class Kisi string ad; string soyad; public string Ad get return ad; grup ad = value; public string Soyad get return soyad; seki soyad = value;

The idea is that you hide the implementation details from the user, and instead provide them with a stable interface. This is to reduce dependency on details that might change in the future.

Then later if you decide to convert the actual data store from a List to a Dictionary C# IList Nasıl Kullanılır and expose the dictionary keys bey the actual value for the property (I have had to do exactly this before). Then consumers who have come to expect that their changes will be reflected inside of your class will no longer have that capability. That's a big mesele! If C# IList Nerelerde Kullanılıyor you expose the List as an IEnumerable you gönül comfortably predict that your collection is derece being modified externally. That is one of the powers of exposing List bey any of the above interfaces.

Obviously if you are being asked which you use in an interview, you say IList, smile, and both look pleased at yourselves for being C# IList Kullanımı so C# IList Nasıl Kullanılır clever. Or for a public facing API, IList. Hopefully you get my point.

Then I looked in my view(mvc) and found that I actually needed the count method bey 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 derece need.

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

For instance, if you return an IEnumerable, then you are limiting them to iterating -- they emanet't add or remove items from your object, they yaşama only act against the objects. If you need to expose a collection outside of a class, but don't want to let the caller change the collection, this is one way of doing it. On the other hand, if you are returning an empty collection that you expect/want them to populate, then an IEnumerable is unsuitable.

Report this wiki page