UdonSharp
UdonSharp copied to clipboard
Support DeclarationExpression for method calls with out parameters
Feature Description:
If it's possible to implement, it would be nice for UdonSharp to support C#'s DeclarationExpression
for methods with out parameters, such as int.TryParse
. This would allow the following code:
int someValue;
if (int.TryParse(inputField.text, out someValue))
{
// do something with someValue
}
to be condensed into:
if (int.TryParse(inputField.text, out var someValue))
{
// do something with someValue
}
Should probably also support the discard syntax:
var isNumberValid = int.TryParse(inputField.text, out _);
I know it's only a minor improvement to convenience, but it'd be nice to have if it's an easy addition.
This is planned, but potentially requires some changes to how the scope of variables is handled.
Technically in standard C# the someValue
variable on both of the two code blocks in my first post would have the same scoping; it's functionally the same, but cleaner to look at. And the discard syntax simply allows you to ignore the out parameter; it doesn't define a variable at all.