473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Casting to integer

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?

Nov 16 '05 #1
4 4985
Robert Strickland wrote:
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
Nov 16 '05 #2
On Sun, 30 May 2004 14:30:41 -0400, Robert Strickland wrote:
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
Nov 16 '05 #3
Thanks

"Arne Janning" <sp*****************@msn.com> wrote in message
news:O7**************@TK2MSFTNGP09.phx.gbl...
Robert Strickland wrote:
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

Nov 16 '05 #4
Hi Robert,

If you are just getting started, you may want to check out the C# FAQ.
Here's an entry specific to your question:

http://blogs.msdn.com/csharpfaq/arch...30/144652.aspx

Joe
--
Joe Mayo, Author/Instructor
Need C#/.NET training?
visit www.mayosoftware.com
"Robert Strickland" <bs*********@comporium.net> wrote in message
news:eI*************@tk2msftngp13.phx.gbl...
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?

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: jose_luis_fdez_diaz_news | last post by:
Hi, If I don't include <libgen.h> I get then warnig below in regcmp call: warning: improper pointer/integer combination: op "=" but if I include it the warning is not shown, but them program...
10
by: ruroma | last post by:
Hello, I need some help with the following: 1) I need to split a 16bit INT into two 8bit characters, and then be able to join these two characters to form again the original 16bit integer....
61
by: Ken Allen | last post by:
I am relatively new to .Net, but have been using VB and C/C++ for years. One of the drawbacks with VB6 and earlier was the difficulty in casting a 'record' to a different 'shape' so one could...
9
by: Brian | last post by:
Hello! What is the proper syntax for casting? For example, how do I change an Integer in to a String if the variable is called Joe1 and has 20 assigned to it. Thanks, Brian
9
by: Chris Botha | last post by:
Hi, I have an UInt32 and want to stick the value into an Integer and get an Overflow exception, BUT using C# the same value can be casted into an int and the value is as expected. The Hex value is...
4
by: Vincent | last post by:
Regarding the dropdetect function, defined as follows: Sub dropdetect(DropFrm As Form, DropCtrl As Control, Button As Integer, Shift As Integer, X As Single, Y As Single) Is it possible to...
1
by: Jason Huang | last post by:
Hi, In my C# Net 2.0, in a DetailsView I have a row TestStatus, and the output will be interger 0, 1, where the 0 presents Pass, 1 presents Fail. What do I need to do so that the output will...
4
by: mitdej | last post by:
Hi there, I have an several enum types that starts from a nunmber other than 0. For example: public enum InternalStatus { Pending = 1, Ported = 2, Suspended = 3 } I put this values in a int...
0
by: Michael Rudolph | last post by:
Hi DB2 newsgroup, I have encountered a difference between our development DB2 on Windows and the test environment on AIX. If using the LOCATE scalar function with a SMALLINT as LENGTH parameter...
32
by: alex.j.k2 | last post by:
Hello all, I have "PRECISION" defined in the preprocessor code and it could be int, float or double, but I do not know in the code what it is. Now if I want to assign zero to a "PRECISION"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.