Error: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

后端 未结 7 1214
后悔当初
后悔当初 2021-01-07 21:59

I am trying to set a property of my .ascx controls from an .aspx using that control.

So in one of my .aspx which has this control in it, I have the

7条回答
  •  时光取名叫无心
    2021-01-07 22:20

    You can't do that because the Add function returns void, not a reference to the list. You can do this:

    mycontrol.ItemList = new List();
    mycontrol.ItemList.Add(item);
    

    or use a collection initializer:

    mycontrol.ItemList = new List { item };
    

提交回复
热议问题