Convert IEnumerable <string> to IEnumerable <ListItem>
I get this error, which when I try to use the yield return function in C #. The error appears on the selected internal visual studio, and I do not understand it. In my opinion, I convert the string to ListItem and then return the lot as IEnumerable. My understanding of return returns and IEnumerable can be very good, so any help would be appreciated. Commented code is an old curriculum that works correctly.
It is not possible to implicitly convert the type 'System.Collections.Generic.IEnumerable' to 'System.Web.UI.WebControls.ListItem'
public partial class CloseIncident : System.Web.UI.Page
{
private ClevelandIncidentRepository repo = new ClevelandIncidentRepository();
protected void Page_Load(object sender, EventArgs e)
{
SetDropDown(InitialType, repo.GetMainTypes());
}
private void SetDropDown(DropDownList dropDown, IEnumerable<string> items)
{
dropDown.Items.Clear();
dropDown.Text = string.Empty;
dropDown.Enabled = items.Count() > 0;
dropDown.Items.AddRange(ToListItem(items).ToArray());
}
private IEnumerable<ListItem> ToListItem(IEnumerable<string> results)
{
yield return from result in results
select new ListItem(result);
//List<ListItem> items = new List<ListItem>();
//items.AddRange(from result in results
// select new ListItem(result));
//return items;
}
}
+3
3 answers