Implementing IList interface

后端 未结 6 1176
温柔的废话
温柔的废话 2020-12-09 11:29

I am new to generics. I want to implement my own collection by deriving it from IList interface.

Can you please provide me some link to a class

6条回答
  •  北海茫月
    2020-12-09 11:53

    Visual Studio offers an automatic full working implementation of interfaces like IList<>.

    You need only to write something like this code:

    public class MyCollection : IList
    {
        // This line is important. Without it the auto implementation creates only
        // methods with "NotImplemented" exceptions
        readonly IList _list = new List();
    }
    

    (while the line

    readonly IList _list = new List(); 
    

    is the important one!)

    Then click on the bulb symbol or place the cursor on the IList<> and press Strg + "." You will become several implementations offered, like:

提交回复
热议问题