Combining List initializer and object initializer

前端 未结 3 1093
难免孤独
难免孤独 2020-12-18 20:35

Is is possible to combine a List initializer and object initializer at the same time? Given the following class definition:

class MyList : List
{
         


        
3条回答
  •  攒了一身酷
    2020-12-18 21:05

    If you want to get something like this functionality, consider making a constructor argument:

    var x = new CustomList("Hello World") { 1, 2, 3 }
    

提交回复
热议问题