En C# IList Nerelerde Kullanılıyor Sırları
Wiki Article
Do the decoupling capacitors act birli capacitive load to the opamp which is used to make a virtual gorund?
Found this thread while I was looking for a solution to the exact mesele described in the original post. None of the answers met my situation entirely, however. Brody's answer was pretty close. Here is my situation and solution I found to it.
The less popular answer is programmers like to pretend their software is going to be re-used the world over, when infact the majority of projects will be maintained by a small amount of people and however birçok interface-related soundbites are, you're deluding yourself.
Your functions above only care about being able to iterate over a list. Ideally they shouldn't need to know who implements that list or how they implement it.
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.
Convert your IList into List or some other generic collection and then you kişi easily query/sort it using System.Linq namespace (it will supply bunch of extension methods)
Matthew WatsonMatthew Watson 108k1111 gold badges170170 silver badges290290 bronze badges 2 2 This is trivially true for every interface. If you want to follow through with your argument, than you could argue to never use any interface at all, because some implementation of it might throw.
the method, it yaşama make a huge difference -- if they have an array and you're asking for a list, they have to change the array to a list or v.v. whenever calling the method, a total waste of time from both a programmer and performance POV.
Then later if you decide to convert the actual data store from a List to a Dictionary and expose the dictionary keys bey the actual value for the property (I have had to do exactly this before). Then consumers who have come to expect that their changes will be reflected inside of your class will no longer have that capability. That's a big mesele! If you expose the List bey an IEnumerable you güç comfortably predict that your collection is hamiş being modified externally. That is one of the powers of exposing List birli any of the C# IList Kullanımı above interfaces.
I know that IList is the interface and List is the concrete type but I still don't know when to use each one. What I'm doing now is if I don't need the Sort or FindAll methods I use the interface. Am I right? Is there a better way to decide when to use the interface or the concrete type?
Then I C# IList Neden Kullanmalıyız looked in my view(mvc) and found that I actually needed the count method kakım I needed to use a for loop. So in my own application I under estimated what I actually C# IList Kullanımı needed how do you anticipate what someone else will need or derece need.
This will help if you decide to change C# IList Nedir 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.
This works, because only the outer list is created in the first place. You yaşama then insert individual items that are compatible C# IList Nasıl Kullanılır with IList: