Discard variable for OUT parameters
Posted: Tue Nov 19, 2019 9:11 am
C# 7 introduced a very convenient thing (quotation from whatsnew):
In some cases, this is convenient when overloading methods/functions.
Compiling this code generates a warning: XS0219 The variable 'additionalResult ' is assigned but its value is never used
Best regards,
Leonid
Is there something similar in XSharp?Often when deconstructing a tuple or calling a method with out parameters, you're forced to define a variable whose value you don't care about and don't intend to use. C# adds support for discards to handle this scenario. A discard is a write-only variable whose name is _ (the underscore character); you can assign all of the values that you intend to discard to the single variable. A discard is like an unassigned variable; apart from the assignment statement, the discard can't be used in code.
In some cases, this is convenient when overloading methods/functions.
Code: Select all
function MyFunc(x as int, additionalResult out int) as logic
...
return true
function MyFunc(x as int) as logic
local additionalResult as int
return MyFunc(x, out additionalResult)
Best regards,
Leonid