3 ms·
Many of these have a `TryParse` method [1] which makes for nice syntax, and of course then you get a variable of the correct type. if (int.TryParse(userInp
by gregmac 4y ago
Many of these have a `TryParse` method [1] which makes for nice syntax, and of course then you get a variable of the correct type.
if (int.TryParse(userInput, out var number))
{
total += number;
}
This is cleaner code compared to try/catch and usually faster (though debatable if it matters) [2].
[1] https://learn.microsoft.com/en-us/dotnet/api/system.net.ipaddress.tryparse?view=net-7.0 https://learn.microsoft.com/en-us/dotnet/api/system.net.ipad...
[2] https://stackoverflow.com/q/161942 https://stackoverflow.com/q/161942