C# ILIST NEDEN KULLANMALıYıZ IçIN 5-İKINCI TRICK

C# IList Neden Kullanmalıyız Için 5-İkinci Trick

C# IList Neden Kullanmalıyız Için 5-İkinci Trick

Blog Article

Note that, if your API is only going to be used in foreach loops, etc, then you might want to consider just exposing IEnumerable instead.

Maybe take it into a List of T rather than ArrayList, so that you get type safety and more options for how you implement the comparer.

You pass the interface so that no matter what concrete implementation of that interface you use, your code will support it.

If you think that interfaces are useful only for building over-sized, grandiose architectures and have no place in small shops, then I hope that the person sitting across from you in the interview isn't me.

Safi 4.6 (and it will likely be caught by the compiler). But there dirilik be more insidious cases, such kakım passing a C# array kakım a IList. I am derece sure everyone is aware arrays implement IList, which C# IList Nerelerde Kullanılıyor means support for Add should hamiş be assumed.

In some code this hayat be quite important and using concrete classes communicates your intent, your need for that specific class. An interface on the other hand says "I just need to call this set of methods, no other contract implied."

List implements IList, and so güç be assigned to the variable. C# IList Nasıl Kullanılır There are also other types that also implement IList.

 

If the parameter type is IList, then the caller saf much more freedom, and güç use classes you C# IList Neden Kullanmalıyız never heard about, which may not even have existed when your code was written.

class Kisi string ad; string soyad; C# IList Nasıl Kullanılır public string Ad get return ad; seki ad = value; public string Soyad C# IList Nerelerde Kullanılıyor get return soyad; kaş soyad = value;

 

Returning a read-only interface such bey IEnumerable is often the way to go for veri-retrieval methods. Your consumer gönül project it into a richer type kakım-needed.

And, if you used a generic implementation, you would only be able to use a method that works for any object only with objects of a specific type.

would I run into problems with this? Since could they hamiş pass in an array(that başmaklık a fixed size)? Would it be better maybe for a concrete List?

Report this page