Passing an empty array as default value of an optional parameter in C#
Answers
![]()
chkdk
46
Points
2
Posts
|
We can't create compile-time constants of object references. The only valid compile-time constant for reference types you can use is null, so change your code to this:
And inside your method do this:
Posted On:
01-May-2017 02:02
|
NiceOne...
1390
Points
18
Posts
|
The documentation for optional arguments [https://msdn.microsoft.com/en-us/library/dd264739.aspx] says: Each optional parameter has a default value as part of its definition. A default value must be one of the following types of expressions:
Since new string[0] is neither a constant expression nor a new statement followed by a value type, it cannot be used as a default argument value. You can try with null following
Posted On:
01-May-2017 02:49
|