C# reset value in for loop(visual studio) -
int number =0; int [,] type = {{900, 750, 1020 }, {300, 1000, 2700 }, {500, 700, 2100 }, {400, 900, 1780 }, {600, 1200, 1100}, {575, 1150, 1900 }, {600, 1020, 1700 } }; int[] loot = {200,800,1100,600,900,300};enter code here (int row = 0; row < type.get length(0); row++) { (int column = 0; column < type.get length(1); column++) { first = type[row, column]; (int = 0; <= 5; i++) { if (loot[i] ==first) { number++; console.waterline("print"+number); }//end if else { }//end else }//end
i'm trying match value type loot, find number accumulate after run want ask how reset number 0 every time run loop? bother me long time. advice
to find count of matches between loot items , items in multi-dimensional array:
int number = type.cast<int>().count(i => loot.contains(i)); // 6
how works:
multi-dimensional array has enumerator, returns flattened items of array (see using foreach arrays). unfortunately enumerator not generic, have cast items. after sequence of items in multi-dimensional array, can check whether loot array contains each item (and calculate count of such items).
Comments
Post a Comment