c# - How do I make the foreach instruction iterate in 2 places? -
how make foreach instruction iterate both in "files" variable , in "names" array?
var files = directory.getfiles(@".\galleryimages"); string[] names = new string[8] { "matt", "joanne", "robert","andrei","mihai","radu","ionica","vasile"};
i've tried 2 options.. first 1 gives me lots of errors , second 1 displays 8 images of each kind
foreach(var file in files,var in names) { //do stuff }
and
foreach(var file in files) { foreach (var in names) { //do stuff } }
it's not clear you're asking. but, can't iterate 2 iterators foreach; can increment variable in foreach body:
int = 0; foreach(var file in files) { var name = names[i++]; // todo: name , file }
this, of course, assumes files , names of same length.
Comments
Post a Comment