+ 1

(C#)How to print each item of IList<IList<int>

to print Array or 1 dimension List could use for loop(via using Length、count、array[i][j]),but how to print IList<IList<int>?

6th Jun 2019, 2:05 PM
adaruru
adaruru - avatar
3 Réponses
+ 4
Have you tried nested foreach loop? foreach (var list2 in list) { foreach (var element in list2) { Console.WriteLine(element); } Console.WriteLine(); }
6th Jun 2019, 7:33 PM
dρlυѕρlυѕ
dρlυѕρlυѕ - avatar
0
to put LeerCode #15 3Sum to IDE test IList<IList<int>> result = ThreeSum(num); //實作測資 Console.WriteLine("["); foreach (IList<int> i in result) { Console.Write("["); string output=""; foreach (int j in i) { if (output != "") { output += ","; } output+= Convert.ToString(j); } Console.Write(output); Console.WriteLine("]"); } Console.WriteLine("]");
10th Jun 2019, 7:06 AM
adaruru
adaruru - avatar
0
to put LeerCode #15 3Sum to IDE test (for loop) IList<IList<int>> result = ThreeSum(num); //實作測資 Console.WriteLine("["); for( int idxI = 0; idxI < result.Count; idxI++) { IList<int> i = result[idxI]; string output = ""; Console.WriteLine("["); for (int idxJ =0; idxJ < i.Count; idxJ++) { int j = i[idxJ]; if (output != "") { output += ","; } output += Convert.ToString(j); } Console.Write(output); Console.WriteLine("]"); } Console.WriteLine("]");
10th Jun 2019, 3:58 PM
adaruru
adaruru - avatar