Skip to content

Instantly share code, notes, and snippets.

@terror
Created March 9, 2021 21:42
Show Gist options
  • Save terror/5699f3a2256c04e8913d74d4ad11ef68 to your computer and use it in GitHub Desktop.
Save terror/5699f3a2256c04e8913d74d4ad11ef68 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
List<List<int>> arr = new List<List<int>>();
// -> []
for(int i = 0; i < 10; ++i) {
arr.Add(new List<int>());
}
// -> [[], [], [], [], [] ... etc]
for(int i = 0; i < 10; ++i) {
for(int j = 0; j < 10; ++j)
arr[i].Add(j);
}
// I
foreach(List<int> i in arr) {
foreach(int j in i)
Console.Write(j + " ");
Console.WriteLine();
}
// II
for(int i = 0; i < arr.Count; ++i) {
for(int j = 0; j < arr[0].Count; ++j)
Console.Write(j + " ");
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment