Click here to Skip to main content
15,915,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,
I want to know it is possible to have two group in the same instruction FOR EACH; For exemple:

For each [type] as Items in Group1 AndAlso Group2

[Loop]

Next

How i can do that?
I don't want to use two times the instruction FOR EACH.

Somebody can give any idea?
Thanks
Posted

1 solution

Assuming Group1 and Group2 contain the same type elements, then the Linq method Union would do it:
http://msdn.microsoft.com/en-us/library/bb341731.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]
VB
For Each [type] as Items in Group1.Union(Group2)
 
Share this answer
 
Comments
alonetmr 18-Sep-13 5:47am    
Ok, thanks for you answer but, when i use your méthode, how i can recover the data in Group2?
OriginalGriff 18-Sep-13 5:59am    
Look at the link: the Union combines the two Groups to form a new group - so the loop works on both.
alonetmr 18-Sep-13 8:30am    
yeah, i undestard that point. But, i want to know how i can take the data of Group2 in the new group?
The new group has all data information of both groups 1 and 2. So, what is the property who gives tha acces to the data in Group2.
OriginalGriff 18-Sep-13 9:41am    
You can't. Either you have two loops, or you combine the groups to make a single loop - .NET objects do not have a "parent" property which tells you which group it is part of (unless you add one to your class yourself). And what if it is in both groups? Which one is the "parent" then?

What are you trying to do that you think you need this?
alonetmr 18-Sep-13 10:10am    
Thanks for yours answer.
I have two variable (recorddata1 and recorddata2) which each one has many data. Now, this variables are in the same Namespace (same group). I have one restraint, it is forbiden to make two loop for take information of each variable.
In another word i have to take the data stored in each variable. you have another idea to do that?
After i need to put this information in a ListView.
thanks

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