string str="";
int no=Convert.ToInt32(str);

Why do you want to do that? anyway you can do this

using System.Text.RegularExpressions;

   str="";
   int no;
   Regex rxNums = new Regex(@"^\d+$"); // Any positive decimal
   if (rxNums.IsMatch(str))
      {
          no = Convert.ToInt32(str);
      }

Regards.

use Int.TryParse()

This will return 0, if not a valid int

string str="";
int no=Convert.ToInt32(str);

in my way

string str="";
int no = Convert.ToInt32(Val(str));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.