Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best way to avoid the error and get 0 for empty value
Message
From
15/09/2017 18:10:31
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01654373
Message ID:
01654374
Views:
44
>Hi everybody,
>
>I now have a code like this in a few places:
>
>
>parameter.Value = Convert.ToDecimal(parameterValue, CultureInfo.InvariantCulture);
>
>
>In that method I also added CultureInfo.InvarianCulture to conversions to Int, Double, etc.
>
>The problem is that now passing empty string throws an error. I can add checking for empty strings and using "0" instead but is there a more elegant solution so I would not need to fix in many places?
>
>Thanks in advance.

Use TryParse instead.
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform