I am just learning C# and I am trying to learn more about TryParse and how it relates to and interacts with established variables. In the following example I'm simply confirming whether the values in a text box are indeed decimals and that they fall within a given range. Otherwise, I call the BadInput() method which displays an error message.
private void VerifyNums()
{
if (decimal.TryParse(Val1Box.Text, out Val1)&& (val1<=100) && (Val1>=0))
{
if (decimal.TryParse(Val2Box.Text, out Val2) && (Val2 <=100) && (Val2 >=0))
{
if (decimal.TryParse(Val3.Text, out Val3) && (Val3 <100) && (Val3 >=0))
{
GoodInput();
}
else
{
BadInput();
}
}
else
{
BadInput();
}
}
else
{
BadInput();
}
}
First Question: What does OUT do in a TryParse? Does it set Val1 equal to the contents of the text box?
Second Question: Is it possible to Parse and check the variables Val1, Val2 and Val3 and then be able to use them as input or arguments in other methods? If so, how is that done? I have read a lot about OUT and REF I just don't understand how they work.