C#C
C#4y ago
surwren

When to use Null Forgiving (!) vs Non-Nullable casts

int? n = null;
string input;

if (int.TryParse(input,out _))
        {
            n = int.Parse(input);
        }

int[] arr = new int[(int)n];


In this example, n needs to be cast from int? to int

My question is why null forgiving (!) syntax does not seem to work (new int[n!];] and where null forgiving syntax would actually be applicable.
Was this page helpful?