Casting to integer

  • Thread starter Thread starter Robert Strickland
  • Start date Start date
R

Robert Strickland

I have used VB.Net and now learning C#. I have the following line from
vb.net app:

id = CType(Request.QueryString("id"), System.Int32)

where id is type integer. I am trying the same under C# with:

id = (System.Int32)ctx.Request.QueryString["reportid"].ToString();

which gets compile error "(31): Cannot convert type 'string' to 'int'"

Any ideas?
 
Robert said:
I have used VB.Net and now learning C#. I have the following line from
vb.net app:

id = CType(Request.QueryString("id"), System.Int32)

where id is type integer. I am trying the same under C# with:

id = (System.Int32)ctx.Request.QueryString["reportid"].ToString();

which gets compile error "(31): Cannot convert type 'string' to 'int'"

Hi Robert,

use int.Parse()

Cheers

Arne Janning
 
Thanks

Arne Janning said:
Robert said:
I have used VB.Net and now learning C#. I have the following line from
vb.net app:

id = CType(Request.QueryString("id"), System.Int32)

where id is type integer. I am trying the same under C# with:

id = (System.Int32)ctx.Request.QueryString["reportid"].ToString();

which gets compile error "(31): Cannot convert type 'string' to 'int'"

Hi Robert,

use int.Parse()

Cheers

Arne Janning
 
I have used VB.Net and now learning C#. I have the following line from
vb.net app:

id = CType(Request.QueryString("id"), System.Int32)

where id is type integer. I am trying the same under C# with:

id = (System.Int32)ctx.Request.QueryString["reportid"].ToString();

which gets compile error "(31): Cannot convert type 'string' to 'int'"

Any ideas?


Try using Convert.To... :

int id = Convert.ToInt32 (sMyString);

Regards,
Peter
 
Back
Top