Simple stupid foreach loop question
- by user281180
In the code below i`m trying to read a list of selected projects and a list of all projects available.
I want to store the all the projects that have not been selected from the list of all projects. But with the code below, I`m having list of all projects...Where and how to break the second loop incase projectId.Value == selectedProjectId.Value ?
public IEnumerable NotselectedProjects;
public IEnumerable NotSelectedProjects()
{
if (this.NotselectedProjects == null)
{
List<SelectListItem> result = new List<SelectListItem>();
foreach (var selectedProjectId in selectedProjects)
{
foreach (var projectId in projectLists)
{
if (projectId.Value != selectedProjectId.Value)
{
result.Add(new SelectListItem
{
Selected = false,
Text = projectId.Text,
Value = projectId.Value
});
this.NotselectedProjects = result.AsEnumerable();
}
}
}
}
return this.NotselectedProjects;
}