Some time we have required to check the value of string is Number or not if it no then offcourse our task on these like sum, avg, max etc etc but somehow it contain string value is not Numeric then its panic . Then what is the solution
Solution :
string strValue = "ABC";
double Num;
bool isNum = double.TryParse(Str, out Num); // out parameter are used
if (isNum)
Response.Write(Num.ToString()); // you use here your label id or other thing
else
Response.Write("Invalid number");
// you use here your label id or other thing
Simply check the no if it is numeric then perform the action other wise no action performed.
Below is the simple example .
there are a method in C# which check the datavalue. Method name is TryParse
it returns always boolean value.
Solution :
string strValue = "ABC";
double Num;
bool isNum = double.TryParse(Str, out Num); // out parameter are used
if (isNum)
Response.Write(Num.ToString()); // you use here your label id or other thing
else
Response.Write("Invalid number");
// you use here your label id or other thing
Excellent Post. Also visithttp://www.msnetframework.com/#aspnet.php
ReplyDeleteHi Rohit,
ReplyDeleteI am not expert in .Net as working in other technologies but i must say here your efforts towards understanding of basic concept is admirable. Keep it up !!
Thanks,
Siddhartha Pandey