Değil Hakkında Detaylar bilinen C# IList Kullanımı

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.

C# List muhtevaindeki verileri yazdırmak bâtınin kötüdaki iki döngüden biri kullanılarak değerleri ekrana yazdırma fiillemi örgülabilir.

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 birli a parameter communicates a similar message "I need a collection of strings, don't worry though, I won't change it."

It's more nuanced than that. If you are returning an IList kakım part of the public interface to your library, you leave yourself interesting options to perhaps make a custom list in the future.

Use whatever you want. It's your method. You're the only one who gets to see the internal implementation details of the method.

I would turn the question around a bit, instead of justifying why you should use the interface over the concrete implementation, try to justify why you would use the C# IList Nasıl Kullanılır concrete implementation rather than the interface. If you yaşama't justify it, use the interface.

+1 for all of us who hate it when a small C# IList Kullanımı app is loaded with interfaces and clicking on "find definition" takes us somewhere OTHER than the source of the sorun... Dirilik I borrow the phrase "Architecture Astronauts"? I sevimli see it will come in handy.

class Kisi string ad; string soyad; public string Ad get return ad; grup ad = value; public string Soyad C# IList Nasıl Kullanılır get return soyad; takım soyad = value;

If the parameter type is IList, then the caller başmaklık much more freedom, and yaşama use classes you never heard about, which may derece even have existed when your code was written.

Collaborate with us on GitHub The source for this content yaşama be found on GitHub, where you sevimli also create and review issues and pull requests. For more information, see our contributor guide.

 

Returning a read-only interface such birli IEnumerable is often the way to go for data-retrieval methods. Your consumer yaşama project it into a richer type birli-needed.

You accept an Interface birli a parameter for a method because that allows the caller to submit different concrete types as arguments. Given your example C# IList Nerelerde Kullanılıyor method LogAllChecked, the parameter someClasses could be of various types, and for the person writing

This works, because only the outer list is created in the first place. You gönül then insert individual C# IList Nedir items that are compatible with IList:

Leave a Reply

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