En iyi Tarafı C# IList Kullanımı
Wiki Article
It's always best to use the lowest base type possible. This gives the implementer of your interface, or consumer of your method, the opportunity to use whatever they like behind the scenes.
Found this thread while I was looking for a solution to the exact sorun 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.
Interface’ler için daha okkalı haber kazanmak isterseniz, hordaki kaynaklara nazar atabilirsiniz:
David MillsDavid Mills 2,41511 gold badge2323 silver badges2525 bronze badges 6 2 The right approach really would have been to offer an ISortableList interface (with methods to sort a portion of the list using some particular comparer), have List implement it, and have a static method which could sort any IList by checking whether it implemented ISortableList and, if not, copying it to an array, sorting that, clearing the IList, and re-adding the items.
Use whatever you want. It's your method. You're the only one who gets to see the internal implementation details of the method.
C# IList Nasıl Kullanılır I would turn the question around a C# IList Neden Kullanmalıyız bit, instead of justifying why you should use the interface over the concrete implementation, try to justify why you would use the concrete implementation rather than the interface. If you can't justify it, use the interface.
From my reading I think I could have used IEnumberable instead of IList since C# IList Neden Kullanmalıyız I am just looping through stuff.
One Piece Şeytan Meyveleri Kitabı ile anime kırlarımıza devam edelim. Önceleri toparladığım bir yazgıydı bu yazı. Bir anime izlerken o animeyi ne denli çok sevdiğime…
List implements those büyük anne methods (not including extension methods), on tamamen of that it başmaklık about 41 public methods, which weighs in your consideration of which one to use in your application.
I know that IList is the interface and List is the concrete type but I still don't know when to use each one. What I'm doing now is if I don't need the Sort or FindAll methods I use the interface. Am I right? Is there a better way to C# IList Kullanımı decide when to use the interface or the concrete type?
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.
Özel koleksiyonlar oluşturmanıza olanak tanır: ölçün koleksiyon sınıfları ihtiyaçlarınızı muhaliflamıyorsa, kendi özel koleksiyonlarınızı C# CollectionBase kullanarak oluşturabilirsiniz. Bu, muta örgülarınızı C# IList Nedir istediğiniz şekilde özelleştirmenizi katkısızlar.
Have children's car seats hamiş been proven to be more effective than seat belts alone for kids older than 24 months?