Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong on this Decimal.TryParse?

Tags:

c#

tryparse

Code :

Decimal kilometro = Decimal.TryParse(myRow[0].ToString(), out decimal 0);

some arguments are not valid?

like image 614
markzzz Avatar asked Dec 14 '12 11:12

markzzz


People also ask

What is decimal TryParse?

TryParse(String, NumberStyles, IFormatProvider, Decimal) Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format. A return value indicates whether the conversion succeeded or failed.

What does TryParse mean?

TryParse is . NET C# method that allows you to try and parse a string into a specified type. It returns a boolean value indicating whether the conversion was successful or not. If conversion succeeded, the method will return true and the converted value will be assigned to the output parameter.

What is integer TryParse?

TryParse(String, Int32) Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded.

What is TryParse C #?

In C#, Char. TryParse() is Char class method which is used to convert the value from given string to its equivalent Unicode character.


1 Answers

out decimal 0 is not a valid parameter - 0 is not a valid variable name.

decimal output;
kilometro = decimal.TryParse(myRow[0].ToString(), out output);

By the way, the return value will be a bool - from the name of the variable, your code should probably be:

if(decimal.TryParse(myRow[0].ToString(), out kilometro))
{ 
  // success - can use kilometro
}

Since you want to return kilometro, you can do:

decimal kilometro = 0.0; // Not strictly required, as the default value is 0.0
decimal.TryParse(myRow[0].ToString(), out kilometro);

return kilometro;
like image 98
Oded Avatar answered Oct 30 '22 11:10

Oded