Simple stupid foreach loop question

Posted by user281180 on Stack Overflow See other posts from Stack Overflow or by user281180
Published on 2010-03-30T06:24:44Z Indexed on 2010/03/30 6:33 UTC
Read the original article Hit count: 273

Filed under:

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;

    }

© Stack Overflow or respective owner

Related posts about c#