I am learning C# in school, and I am already used to coding in Python. Trying to take what I have learned in Python and apply it in C# has worked pretty well so far, but I have ran into an issue. I just CANT wrap my head around how lists work in C#
Say I'm working on a simple game, Tic Tac Toe. In python, I would make a list, with 3 lists inside, and then have THOSE lists contain the playing field, like this:
# First I generate the lists within a list:
screenMatrix = []
for y in range(3):
temp = []
for x in range(3):
temp.append(" ")
screenMatrix.append(temp)
# Then I can just change the board at specific X and Y coordinates
screenMatrix[0][2] = "1" #This is top right
screenMatrix[1][1] = "2" #This is the middle
# And then I could print it out like this:
for row in screenMatrix:
print(f"{screenMatrix[row][0]}{screenMatrix[row][1]}{screenMatrix[row][2]}")
This is a very simple way of doing this, but that is besides the point. How would I write in C# to get this exact same functionality? (being able to change items based on X,Y coords)
If someone could translate the code I wrote into C#, that might help me understand the structure.
>`, but `screenMatrix` looks like an [array](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/) to me (see multidimentional and jagged arrays), rather than *list*, `.append` is probably only relevant to instantiating.
– Sinatr Nov 05 '20 at 14:28>{ new List{0,0,0},
new List{0,0,0},
new List{0,0,0}
};
ScreenMatrix[0][0] = 1;
foreach (var row in ScreenMatrix){
Console.WriteLine($"{row[0]}{row[1]}{row[2]}");
}`
I tried this, and it seems to do what I want, but is this not the "proper" or the smart way of doing it then?
– TayIsAsleep Nov 05 '20 at 14:34