En Kuralları Of C# IList Neden Kullanmalıyız

You cannot predict the future. Assuming that a property's type will always be beneficial birli a List is immediately limiting your ability to adapt to unforeseen expectations of your code.

Aşağıdaki şekilde Kisi adında oluşturduğumuz klası oluşturduğumuz liste nesnesine ekleyelim.

If someone passes you an Array or a List, your code will work fine if you check the flag every time and have a fallback... But really; who does that?

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.

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.

The speed difference is sufficiently great that in many cases it may be faster to copy a list to an array, sort the array, and copy the list back, than to try to have a sort routine process the list in place.

use LINQ to perform the conversion of your existing List when you return it - but it would be better to just create a more appropriate type to start with, birli shown above.

GitHub'da bizimle işbirliği dokuman Bu derunğin kaynağı GitHub'da bulunabilir; burada ayrıca problemlerı ve çekme isteklerini oluşturup gözden geçirebilirsiniz. Henüz bir tomar bilgi midein katkıda mevcut kılavuzumuzu inceleyin.

but my mesele is that i am derece understanding what is its use and when to use C# IList Neden Kullanmalıyız it . So i hope that anyone dirilik help me . Thanks .

Taking LinkedList vs taking List vs IList all communicate something of the performance guarantees required by the code being called.

If you're working within a single method (or even in a single C# IList Nasıl Kullanılır class or assembly in some cases) and no one outside is going to see what you're doing, use the fullness of a List. But if you're interacting with outside code, like when you're returning a list from a method, then you only want C# IList Neden Kullanmalıyız to declare the interface without necessarily tying yourself to a specific implementation, especially if you C# IList Nerelerde Kullanılıyor have no control over who compiles against your code afterward.

Bu örnekte, Student isminde bir klas ve StudentCollection isminde CollectionBase C# IList Neden Kullanmalıyız sınıfından türeyen özel bir derlem derslikı oluşturduk.

This will help if you decide to change the implementation of your class later to use a different concrete class. In that case the users of your library won't need to update their code since the interface doesn't change.

So I have been playing around with some of my methods on how to do this. I am still hamiş sure about the return type(if I should make it more concrete or an interface).

Leave a Reply

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