C# Multidimensional and Jagged Arrays
Represent a room grid and a set of rows whose lengths can differ.
How it works
A rectangular array has a fixed extent in each dimension and uses comma-separated indices. A jagged array is an array whose elements are references to other arrays; each row can have a different length or be absent if not initialized. Choose the shape from the data rather than converting syntax mechanically. A classroom seating grid may be rectangular, while workshop groups with different sizes can be jagged. Validate every selected dimension before indexing input-derived positions.
Run it locally
Use the .NET 10 SDK with C# 14 in a separate console lab. Create an empty project once with dotnet new console --framework net10.0, then replace Program.cs with this complete source and add any supporting files shown. Keep only one lesson entry point in the project. C# does not currently run in Bhylu’s browser playground. Apache, PHP and MySQL are not needed.
dotnet build -p:LangVersion=14.0 -p:Nullable=enable -p:TreatWarningsAsErrors=true
dotnet run --no-buildUse the SDK’s project workflow; the review compiles against its matching reference assemblies and executes the results without external NuGet packages. File-writing examples belong in a private empty lab directory.
Example
using System;
internal static class Program
{
private static void Main(string[] args)
{
int[,] grid = { { 2, 3 }, { 4, 5 } };
int[][] groups = { new[] { 1, 2 }, new[] { 3 } };
Console.WriteLine($"Grid corner: {grid[1, 1]}");
Console.WriteLine($"Rows: {grid.GetLength(0)}; second group: {groups[1].Length}");
}
}
Expected result
Grid corner: 5
Rows: 2; second group: 1
GetLength selects the extent of one rectangular dimension. The jagged example asks the selected row array for its own length. A new jagged outer array does not automatically create all inner arrays. A fixed fixture can initialize them together, while an input parser must separately enforce row presence and allowed sizes.
Consult Microsoft’s C# documentation for language and library contracts, including target-framework and version requirements.