AçıKLAMASı C# ILIST NEDEN KULLANMALıYıZ HAKKıNDA 5 BASIT TABLOLAR

Açıklaması C# IList Neden Kullanmalıyız Hakkında 5 Basit Tablolar

Açıklaması C# IList Neden Kullanmalıyız Hakkında 5 Basit Tablolar

Blog Article

The above is an IList itself as this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but not sure. Still, I yaşama't figure out what the user would 100% need(that's where returning a concrete başmaklık an advantage over).

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, hamiş 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."

Why does the Clausius inequality involve a single term/integral if we consider a body interacting with multiple heat sources/sinks?

Basically, I need to see some actual code examples of how using IList would have solved some problem over just taking List into everything.

You emanet have an instance of an interface, but you need to initialize it with a class that implements that interface such kakım:

StuartLCStuartLC 106k1818 gold badges216216 silver badges289289 bronze badges Add a comment  

In fact, any time you are using reflection IList is more convenient than IList-of-T, since generics and reflection don't play nicely together. It güç be done, but it is a pain. Unfortunately since IList-of-T doesn't C# IList Kullanımı derive from IList there are cases where this dirilik özne - but it is a good C# IList Nerelerde Kullanılıyor 95% rule.

In most cases, if you are using a List C# IList Nasıl Kullanılır and you think you could use a narrower interface instead - why hamiş IEnumerable? This is often a better fit if you don't need to add items. C# IList Nasıl Kullanılır If you need to add to the collection, use the concrete type, List.

Want to improve this question? Update the question so it güç be answered with facts C# IList Kullanımı and citations by editing this post.

Obviously if you are being asked which you use in an interview, you say IList, smile, and both look pleased at yourselves for being so clever. Or for a public facing API, IList. Hopefully you get my point.

Brad LeachBrad Leach 17k1818 gold badges7373 silver badges8888 bronze badges 1 3 It will create a new enumerable, which may hamiş be desirable in some scenarios. You cannot sort an IList in-place through the interface except by using ArrayList.Adapter method in my knowledge.

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.

Encapsulation relies on telling clients as little about the implementation of your class kakım possible. If you return a concrete List, you hayat't then change to some other better type without forcing all of your clients to re-compile/update.

Report this page