Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
try
    {
        List<int> taskTypeList = new List<int>();

        var flowBranches = from flow in _db.FlowBranches
                .Where(x => x.FlowID == flowID)
                .Select(x => new { x.FirstTaskTypeID, x.SecondTaskTypeID, x.DependencyType }).ToList()
                           select flow;

        foreach (var item in flowBranches)
        {
            var itemQuery = from y in _db.TaskTypes
                            .Where(x => x.TaskTypeId == item.FirstTaskTypeID)
                            .Select(x => x.TaskTypeId).ToList()
                            select y;

            taskTypeList.AddRange(itemQuery);
        }

        foreach (var taskId in taskTypeList)
        {

            //Do stuff
        }

        return 0;
    }


What I have tried:

Hello,

I wonder if any of you can give me an idea of ​​how to iterate the first item in a list and then iterate the second element in a foreach.

thanks
Posted
Updated 28-Mar-16 8:28am
Comments
OriginalGriff 28-Mar-16 10:44am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps an example would help us to understand what you are trying to do?
Use the "Improve question" widget to edit your question and provide better information.
Sascha Lefèvre 28-Mar-16 11:36am    
Not clear enough.
Matt T Heffron 29-Mar-16 16:16pm    
So... is there some clarification you're going to add?
Is your question solved?

1 solution

It appears that you just want (one of) the foreach statements to iterate over only the first two items of the collection. If that is your question, then just use the .Take(2) method on the collection in the statement. For example:
C#
foreach (var item in flowBranches.Take(2))
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900