Many developers will face problem when converting string to particular numeric datatype. Some times it will give error if string is non numeric. Non numeric string means, it may contain any extra string character or may be white space with numeric value. In that case it give error like "Input string was not in a correct format" We overcome this problem by using TryParse method for numeric datatype conversion of like int,decimal,long etc. See below example
{ int I = 0; if (int.TryParse("25", out I)) Response.Write(string.Format("Value of I is={0}", I.ToString())); }
Thank You
Published under: Microsoft .NET Tips · · · ·