C#C
C#2y ago
84 replies
ABp16

Explanation for array initialization peculiarities

I'd like to get an explanation for the following behavior :

        Ty[] tys = {};
        Console.WriteLine(tys.Length); // This is fine
        
        // Of is a Ty[]
        var tup = new Ty.Tuple { Of = {} };
        Console.WriteLine(tup.Of.Length); // This causes a null pointer exception


Why does
{}
seem to do something different depending on where it is ?
Was this page helpful?