473,387 Members | 1,572 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,387 software developers and data experts.

testing null for integer type variable

js
I need to test if an integer variable is null or not. I tried to do

int myVairable;
myVariable = Int32.Parse(txtControl1.Text.Trim());
if (myVariable != null) {// do something}

C# does not allow this statement. How do I test an integer to see if it
is null or not? Thanks.

Nov 19 '05 #1
1 2624
The Parse method will throw an ArgumentNullException if the value being
passed is nothing. You can use a Try/Catch to catch the
ArgumentNullException. I'm not a C# programmer, but in VB it would look like:

dim myVariable as integer
Try
myVariable = Int32.Parse(txtControl1.Text.Trim())
'If I get here then all is well. Do something with the number.
myVariable = myVariable * 5

Catch exane as ArgumentNullException
'Value is null; do something else:
lblError.Text = exane.Message

Catch ex as Exception
'To catch all other errors
lblError.Text = ex.Message
End try

Hope this helps.
if (myVariable != null) {// do something}

"js" wrote:
I need to test if an integer variable is null or not. I tried to do

int myVairable;
myVariable = Int32.Parse(txtControl1.Text.Trim());
if (myVariable != null) {// do something}

C# does not allow this statement. How do I test an integer to see if it
is null or not? Thanks.

Nov 19 '05 #2

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

Similar topics

8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
5
by: John Smith | last post by:
Hey folks, I know this is an old topic, but I can't find a definitive answer on google. How do I tell if an int has been initialized or not? I had been testing it like: if(myInt ==...
2
by: js | last post by:
I need to test if an integer variable is null or not. I tried to do int myVairable; myVariable = Int32.Parse(txtControl1.Text.Trim()); if (myVariable != null) {// do something} C# does not...
15
by: TC | last post by:
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which contains the "index of the row in the DataView...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
35
by: fcvcnet | last post by:
Hi, This is c code , but the question is same to c++ £¨new/delete£©. char* p = malloc(10); strcpy(p, "hello"); printf("%s\n", p); free(p); // free just add p to the free list of memory, and...
27
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1...
42
by: polas | last post by:
Afternoon all, I have some code (which I thought was OK, but now appreciate is probably not by the standard) which contains int a; ...... if (a==NULL) { ....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.