The word you're looking for is "compiler" and it might have helped if you had explained that there was an error and provided the error message in the first place.
This is an example of why you should ALWAYS read the relevant documentation, or at least pay attention to Intellisense as you write your code. The point of a
Try{Parse
method is to try to get a value without throwing an exception. Where exactly do you expect that result to be? That's what that second parameter is for. If the method returns
false
then the
string
could not be parsed and if it returns
true
then the
string
could be parsed and the result is stored in that second parameter. That parameter is the same type as you're calling the method on. If you call
decimal.TryParse
then that second parameter is type
decimal
.
More of then not, you can actually just declare the variable in the method call and let the type be inferred, as you only need to use it inside the
if
block, e.g.
if (decimal.TryParse(inputString, out var outputDecimal))
{
// Use outputDecimal here.
}
You should only declare it outside that block if you actually need to use it outside that block.