Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i change queryString value to (int) [duplicate]

Tags:

c#

int

Possible Duplicate:
How can I convert String to Int?

how can i change queryString value to an (int)

string str_id;
str_id = Request.QueryString["id"];
int id = (int)str_id;
like image 962
Hammam Muhareb Avatar asked Dec 01 '22 20:12

Hammam Muhareb


1 Answers

Use Int32.TryParse Method to get int value safely:

int id;
string str_id = Request.QueryString["id"];
if(int.TryParse(str_id,out id))
{
    //id now contains your int value
}
else
{
    //str_id contained something else, i.e. not int
}
like image 189
horgh Avatar answered Dec 04 '22 11:12

horgh