DüşüNCELER HAKKıNDA BILMEK C# ILIST NEDIR

Düşünceler Hakkında Bilmek C# IList Nedir

Düşünceler Hakkında Bilmek C# IList Nedir

Blog Article

The above is an IList itself birli this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but derece sure. Still, I hayat't figure out what the user would 100% need(that's where returning a concrete saf an advantage over).

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

Using IList instead of List makes writing unit tests significantly easier. It allows you to use a 'Mocking' library to pass and return data.

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.

The preceeding line of code will work, but you will only have the members of IList available to you instead of the full set from whatever class you initialize.

so its safety for you and freedom to the coder who is writing concrete implementation to change or add more functionality to his concrete class.

 

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.

If the parameter C# IList Nedir type is IList, then the caller saf much more freedom, and can use classes you never heard about, which may hamiş even have existed when your code was written.

Then later if you decide to convert the actual veri store from a List to a Dictionary and expose the dictionary keys C# IList Nerelerde Kullanılıyor as 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 sıkıntı! If you expose the List bey an C# IList Nasıl Kullanılır IEnumerable you gönül comfortably predict that your collection is not being modified C# IList Neden Kullanmalıyız externally. That is one of the powers of exposing List birli any of the above interfaces.

IList.IsFixedSize değerinin çakılı bir boyuta malik olup olmadığını IList tamlayan bir kıymetiharbiye alır.

I leave this up to show that if you needed to do it (e.g. the off chance a third party library returned a List that you needed to convert for another 3rd party library), you güç do it this way.

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.

IEnumerable allows you to iterate through a collection. ICollection builds on this and also allows for adding and removing items. IList also allows for accessing and modifying them at a specific index. By exposing the one that you expect your consumer to work with, you are C# IList Nasıl Kullanılır free to change your implementation. List happens to implement all three of those interfaces. If you expose your property bey a List or even an IList when all you want your consumer to have is the ability to iterate through the collection. Then they could come to depend on the fact that they dirilik modify the list.

Report this page