CSharp · Console
using System;
using NUnit.Framework; // Throws NUnit.Framework.AssertionException
#nullable enable
//https://stackoverflow.com/questions/66018737/multidimensional-arrays-nullable-reference-types-and-type-conversion
//https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/arrays#1721-general
// ... the rank_specifiers are read from left to right before the final non-array element type.
// Example: The type in T[][,,][,] is a single-dimensional array of three-dimensional arrays of two-dimensional arrays of int. end example
public class Program
{
public static void Main()
{
Console.WriteLine("Environment version: {0} ({1}), {2}\n", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version, Environment.OSVersion);
string? [,][] d = new string[1,2][]; // Compiles (no surprise)
string? []?[,] f = new string[1,2][]; // Also compiles (surprise!)
Assert.That(d.GetType() == f.GetType()); // No failure
Console.WriteLine($"typeof(string? [,][]) = {typeof(string? [,][])}");
Console.WriteLine($"typeof(string? [,][]).GetElementType().Name = {typeof(string? [,][]).GetElementType()!.Name}");
}
}
//Notes & bookmarks:
//https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/arrays#1721-general
//https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/types#821-general
//obsolete: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/nullable-reference-types-specification.md
//Current: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/nullable-reference-types-specification.md
//https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references
//https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references#generics
//https://github.com/dotnet/roslyn/issues/50967
//https://www.mono-project.com/docs/advanced/runtime/runtime-hacking/
//https://github.com/mono/mono/blob/5d2e3bc3b3c8184d35b2f7801e88d96470d367c4/mono/metadata/class.c#L358
//https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version