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

Wiki 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 kişi't figure out what the user would 100% need(that's where returning a concrete başmaklık an advantage over).

Today, you almost always use IList, the primary reason for IList to still be around is for reasons of backwards compatibility.

Also, it casts IList to IList which has the potential to be dangerous. In most cases that I have seen, List which implements IList is used behind the scenes to implement IList, but this is derece guaranteed and kişi lead to brittle code.

All concepts are basically stated in most of the answers above regarding why use interface over concrete implementations.

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.

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 concrete implementation rather than the interface. If you dirilik't justify it, use the interface.

Object dirilik be a T too. Doing this will save you headache if you decide to use a Stack or some other data structure further down the road. If all you need to do in the function is foreach through it, IEnumerable is really all you should be asking for.

If you specify your methods to return an interface that means you are free to change the exact implementation later on without the consuming method ever knowing.

Whether you return an Interface or a concrete type depends upon what you want to let your callers do with the object you created -- this is an API design decision, and there's no hard and fast rule. You C# IList Nerelerde Kullanılıyor have to weigh their ability to make full use of the object against their ability to easily use a portion of the objects functionality (and of course whether you WANT them to be making full use of the object).

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

kemiller2002kemiller2002 115k2828 gold badges198198 C# IList Nerelerde Kullanılıyor silver badges253253 bronze badges Add a comment  

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 C# IList Neden Kullanmalıyız sort an IList in-place through the interface except by using ArrayList.Adapter method in my knowledge.

You can pass C# IList Nedir a plain array to something which accepts an IList parameter, and then you kişi call IList.Add() and will receive a runtime exception:

Have children's car C# IList Kullanımı seats hamiş been proven to be more effective than seat belts alone for kids older than 24 months?

Report this wiki page