✅ how to learn C# for mono game?

Hey, im interested in gamedev, what to make games with monogame, but i dont have a lot of c# knowledge, what to do before starting monogame? here is an example code that i just dont seem to understand how it works:
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;

public class MapData
{
[JsonPropertyName("width")]
public int Width { get; set; }

[JsonPropertyName("height")]
public int Height { get; set; }

[JsonPropertyName("tiles")]
public int[][] Tiles { get; set; }
}

class Program
{
static void Main()
{
try
{
// Read the JSON file from output directory
string json = File.ReadAllText("map.json");

// Deserialize JSON into C# object
MapData map = JsonSerializer.Deserialize<MapData>(json);

Console.WriteLine($"Width: {map.Width}, Height: {map.Height}\n");

Console.WriteLine("Tiles:");
for (int y = 0; y < map.Tiles.Length; y++)
{
for (int x = 0; x < map.Tiles[y].Length; x++)
{
Console.Write(map.Tiles[y][x] + " ");
}
Console.WriteLine();
}

// Optional: Convert jagged array to 2D array
int rows = map.Tiles.Length;
int cols = map.Tiles[0].Length;
int[,] grid = new int[rows, cols];
for (int y = 0; y < rows; y++)
for (int x = 0; x < cols; x++)
grid[y, x] = map.Tiles[y][x];

Console.WriteLine($"\nTile at (2,3) in 2D array: {grid[2, 3]}");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;

public class MapData
{
[JsonPropertyName("width")]
public int Width { get; set; }

[JsonPropertyName("height")]
public int Height { get; set; }

[JsonPropertyName("tiles")]
public int[][] Tiles { get; set; }
}

class Program
{
static void Main()
{
try
{
// Read the JSON file from output directory
string json = File.ReadAllText("map.json");

// Deserialize JSON into C# object
MapData map = JsonSerializer.Deserialize<MapData>(json);

Console.WriteLine($"Width: {map.Width}, Height: {map.Height}\n");

Console.WriteLine("Tiles:");
for (int y = 0; y < map.Tiles.Length; y++)
{
for (int x = 0; x < map.Tiles[y].Length; x++)
{
Console.Write(map.Tiles[y][x] + " ");
}
Console.WriteLine();
}

// Optional: Convert jagged array to 2D array
int rows = map.Tiles.Length;
int cols = map.Tiles[0].Length;
int[,] grid = new int[rows, cols];
for (int y = 0; y < rows; y++)
for (int x = 0; x < cols; x++)
grid[y, x] = map.Tiles[y][x];

Console.WriteLine($"\nTile at (2,3) in 2D array: {grid[2, 3]}");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
5 Replies
Indie Vibes Arcade
what should i do to understand and where should i learn?
Indie Vibes Arcade
and how do you go about that?
Indie Vibes Arcade
after learning basic c#, where can i learn to read files for tilemaps and stuff ok thanks, i know this one, i just dont understand stuff like stream reader and all of that yea, but the long youtube tutorials i found dont cover reading files ok thanks, probably jumping to much, need to start from 0 i do have some python basics thanks for the help!

Did you find this page helpful?