Suppose we have a string that can have null or blank values or can have a valid value also. We need to convert that to decimal. the below are the ways to do so
a) string str = "";
decimal d= String.IsNullOrEmpty(str)?0M: Convert.ToDecimal(str);
b) string str = "";
decimal d= String.IsNullOrEmpty(str)?default(decimal) : Convert.ToDecimal(str);
c) string str = "";
decimal number;
decimal d= Decimal.TryParse (str , out number) ? number : default(decimal);
Hope this will be helpful