It's worth to mention that from C# 8.0 you can have a nullable reference type:
https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types
but as others mentioned this:
private readonly decimal?[] _amounts = new decimal?[_count];
means the value-type elements in array can be null. decimal
is value type and normally you can't assing null to it but if you have decimal?
then you can.
With C# 8.0 and nullable reference types feature enabled you should declare reference types as nullable reference types if you want to assing null to them, otherwise you'll get compiler warning by default. You can declare one like this:
private decimal?[]? _amounts;
Now it means that both elements in array can be null and entire array (_amounts variable) may be null.
So in general the question mark after element value type ?
and before []
->
SomeValueType?[]
means that elements in array can be null. From C# 8.0 (with feature enabled in project) question mark ?
after array type SomeArrayType[]
->
SomeArrayType[]?
means that you can assign null to variable that holds reference to the array.