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

后端 未结 4 595
半阙折子戏
半阙折子戏 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:42

    No, but if you changed your AddRange signature to return the list instance, then you could at least do

    var list = new List().AddRange(array, n);
    

    which imho is probably clearer than overloading the constructor anyway.

提交回复
热议问题