EN C# ILIST NERELERDE KULLANıLıYOR SıRLARı

En C# IList Nerelerde Kullanılıyor Sırları

En C# IList Nerelerde Kullanılıyor Sırları

Blog Article

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

What US checks and balances prevent the FBI from raiding politicians unfavorable to the federal government?

Say I have a function that returns IEnumerable, inside the function I may use a List for an internal backing store to generate my collection, but I only want callers to enumerate it's contents, not add or remove. Accepting an interface as a parameter communicates a similar message "I need a collection of strings, don't worry though, I won't change it."

The following example demonstrates the implementation of the IList interface to create a simple, fixed-size list.

In the end, you might need to replace an implementation for any reason; performance is just one possibility. Regardless of the reason, using the least-derived type possible will reduce the need for changes in your code when you change the specific run-time type of your objects.

Yes, you may never change that veri type from a List but you can be sure that if you have to. Your code is ready for it.

Bu kent, istenmeyenleri azaltmak karınin Akismet kullanıyor. Tefsir verilerinizin nasıl konulendiği hakkında henüz ziyade vukuf edinin.

Ask those people what they'd like the methods to return. Your question is fundamentally "how do I know what software to write?" You know by getting to know what problems your customer başmaklık to solve, and writing code that solves their problems.

If you started with a concrete type C# IList Nasıl Kullanılır and you decided to change to another one, even if it uses the same interface, you're going to break someone else's code unless you started off with an interface or abstract C# IList Nedir base type. Share Improve this answer Follow

What US checks and balances prevent the FBI from raiding politicians unfavorable to the federal government? more hot questions

private List _numbers; // callers birey add/update/remove elements, but cannot reassign a new list to this property

rajeshrajesh 39133 silver badges22 bronze badges 1 8 Excellent, clear answer, which I marked bey helpful. However, I would add C# IList Neden Kullanmalıyız that for most C# IList Neden Kullanmalıyız developers, most of the time, the tiny difference in izlence size and performance is not worth worrying about: if in doubt, just use a List.

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

I read a lot of posts saying C# IList Nedir how this makes it easier to change the implementation later on, but I just don't fully see how that works.

Report this page