Nullable Array Notation

Viewed 1857

I am new to nullable.

Is there a meaningful difference between the possible notations? string?[] str string[]? str and even string?[]? str seems to all be valid

1 Answers

When we put ? after reference type we allow the instance to be null. So we have

  • string?[] - string array where we allow the items to be null (but array itself can't be null)
  • string[]? - string array which can be null itself (but it can't have null items)
  • string?[]? - both array and its items allowed to be null
Related