✅ 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);
        }
    }
}
Was this page helpful?