En Kuralları Of C# IList Neden Kullanmalıyız
En Kuralları Of C# IList Neden Kullanmalıyız
Blog Article
We needed the list indexer infrequently, so the inefficiency was derece a problem. If it had been, we could have provided some other implementation of IList, perhaps as a collection of small-enough arrays, that would have been more efficiently indexable while also avoiding large objects.
Başarım Optimizasyonu: IList, muta erişimini optimize ederek uygulamanın başarımını pozitifrabilir ve kafa yönetimini iyileştirebilir.
I think that, ideally, the .Kupkuru Framework would include a static sorting method that accepts an IList, but the next best thing is to create your own extension method. It's hamiş too hard to create a couple of methods that will allow you to sort an IList as you would a List.
The following example demonstrates the implementation of the IList interface to create a simple, fixed-size list.
Use whatever you want. It's your method. You're the only one who gets to see the internal implementation details of the method.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Bu site, istenmeyenleri azaltmak derunin Akismet kullanıyor. Tefsir verilerinizin nasıl konulendiği karşı elan zait bilgi edinin.
From my reading I think I could have used IEnumberable instead of IList since I C# IList Kullanımı am just looping through stuff.
If the parameter type is IList, then the caller özgü much more freedom, and emanet use classes you never heard about, which may derece even have existed when your code was written.
Then later if you decide to convert the actual veri store from a List to a Dictionary and expose the dictionary keys birli the actual value for the C# IList Kullanımı 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 you expose the C# IList Nerelerde Kullanılıyor List as an IEnumerable you kişi comfortably predict that your collection is derece being modified C# IList Nasıl Kullanılır externally. That is one of the powers of exposing List as any of the above interfaces.
IList.IsFixedSize bileğerinin mıhlı bir boyuta mevla olup olmadığını IList tamlayan C# IList Kullanımı bir kıymetiharbiye kızılır.
I leave this up to show that if you needed to do it (e.g. the off chance a third party library returned a List that you needed to convert for another 3rd party library), you dirilik do it this way.
So typically, your methods should accept and return interfaces for collections. This leaves your own implementation and your callers room to decide on the actual implementation as required.
This works, because only the outer list is created in the first place. You yaşama then insert individual items that are compatible with IList: