Is it possible to create constructor-extension-method ? how?

后端 未结 4 588
半阙折子戏
半阙折子戏 2020-12-30 18:22

Is it possible to add a constructor extension method ? I want to add a List< T > constructor to receive specific amount of bytes out of a given partially filled buffer (w

4条回答
  •  执笔经年
    2020-12-30 18:49

    I know this is a bump, just wanted to point out you can inherit the List class and do something like this:

    class List : System.Collections.Generic.List
        {
            public List(T[] a, int n)
                : base()
            {
                    AddRange(a, n);
            }
        }
    

提交回复
热议问题