Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nullable Array Notation

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

like image 336
Henrik Halbritter Avatar asked Jun 01 '21 14:06

Henrik Halbritter


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
like image 194
Dmitry Bychenko Avatar answered Sep 29 '22 10:09

Dmitry Bychenko