php - How to use two arrays in one foreach loop using C# -
how loop through 2 arays using foreach
loop? found previously, that's php not c#
$images = array('image1', 'image2', ...); $descriptions = array('description1', 'description2', ...); foreach (array_combine($images, $descriptions) $image => $desc) { echo $image, $desc; }
my thought have following
string[] valuea = {1,2,3} string[] valueb = (a,b,c} foreach(something here valuea && valueb) { methodnamehere(valuea, valueb); //method calling requires 2 values }
you zip operation come in .net 4 in feature. on link1 , link2 description.
you right like:
var alpha = new [] { a, b, c, d }; var day = new [] { "s", "s", "m", "t" }; var alphasanddays = alpha.zip(day, (n, w) => new { alpha = n, day = w }); foreach(var ad in alphasanddays) { console.writeline(aw.alpha + aw.day); }
Comments
Post a Comment