-
foreach loops
Hi,
I have a Lists of certain objects, and am looping through all combos of them like
foreach(object o1 in theobjects){
foreach(object o2 in theobjects){
foreach(object o3 in the objects){
}
}
}
However I dont want to double up on myself, e.g. o1[element 1]o2[element 1]o3[element 2], can be regarded as the same as o1[element 1]o2[element 2]o3[element 1], (i.e. switching the last two etc).
I just want to consider o1[element 1]o2[element 2]o3[element 3],o1[element 2]o2[element 1]o3[element 3],o1[element 3]o2[element 1]o3[element 2]
Hope this makes sense...
-
Re: foreach loops
Not a good answer i know, but something like this:
Code:
For each object x in objectList
{
trycast the object to its correct type then:
if (new object = type 1)
{}
if (new object = type 2)
{}
.......
}
why are you using object anyway, so you have a List<object>? What is the base class for the object? List<baseclass> would be better.
-
Re: foreach loops
foreach implies you want to do something for each object. You dont.
Code:
for (int i=0; i<count-2;++i)
for (int j=i+1; j<count-1; ++j)
for (k=j+1;k<count ++k)