How to discard a value in X#?
Posted: Mon Nov 14, 2022 4:35 pm
Hello
when I want to convert a string to an int, I use Int.TryParse which returns true, when the string can be parsed and also has an out param with the string value.
But how can I handle the situation, when I only want to check, if the string can be parsed as Int,. To use TryParse, I have to define a variable for the out parameter and if I don't use it in the code, I'll get a warning.
In C#, I would use _ to discard the value.
Is there a way to do the same in x# (2.13)
Kind regards
Volkmar
when I want to convert a string to an int, I use Int.TryParse which returns true, when the string can be parsed and also has an out param with the string value.
Code: Select all
var str := "123"
if int.TryParse(str, out var strAsInt)
// do something with the value strAsInt
endif
In C#, I would use _ to discard the value.
Code: Select all
static bool StringIsInt(string value)
{
return int.TryParse(value, out _);
}
Kind regards
Volkmar