UdonSharp icon indicating copy to clipboard operation
UdonSharp copied to clipboard

Support DeclarationExpression for method calls with out parameters

Open ArcanoxDragon opened this issue 4 years ago • 2 comments

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.

ArcanoxDragon avatar Jun 21 '20 17:06 ArcanoxDragon

This is planned, but potentially requires some changes to how the scope of variables is handled.

MerlinVR avatar Jun 22 '20 21:06 MerlinVR

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.

ArcanoxDragon avatar Jun 22 '20 23:06 ArcanoxDragon