Alex Rivera | Logout

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

Asked 2009-12-08T17:01:22.770
22

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 following code trying to set the ItemsList property of my embedded .ascx:

Item item = GetItem(itemID);
myUsercontrol.ItemList = new List<Item>().Add(item);

The property in the .ascx that I'm trying to set looks like this:

public List<Item> ItemsList
{
   get { return this.itemsList; }
   set { this.itemsList = value; }
}

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

So I don't get where it's getting void as part of the property?...weird.

Edit
Report

1 Answer

1
new List<Item>().Add(item);

This line returns void.

Try:

var list = new List<Item>();
list.Add(item);
ItemListt.ItemList = list;
answered 2009-12-08T17:05:23.807

Your Answer