473,326 Members | 2,815 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,326 software developers and data experts.

Check null

RP
I have a member variable of a class of type "int", and while assigning
value to it in a constructor, I want to check whether it is a null. I
am using following code:

if (NewMember.BPLNo == null)
NewMember.BPLNo = 0;

But, Visual Studio 2005 is giving warning that variables with type
'int' cannot be 'null'. How to check this?

I also want to know is there any functions like IsNumeric, IsString
etc. in C#.

Nov 12 '07 #1
4 5050
RP wrote:
I have a member variable of a class of type "int", and while assigning
value to it in a constructor, I want to check whether it is a null. I
am using following code:

if (NewMember.BPLNo == null)
NewMember.BPLNo = 0;

But, Visual Studio 2005 is giving warning that variables with type
'int' cannot be 'null'. How to check this?

I also want to know is there any functions like IsNumeric, IsString
etc. in C#.
No need to check, because int can not be null.

int? can be null if you need the capability.

Arne

Nov 12 '07 #2

"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:47***********************@news.sunsite.dk...
RP wrote:
>I have a member variable of a class of type "int", and while assigning
value to it in a constructor, I want to check whether it is a null. I
am using following code:

if (NewMember.BPLNo == null)
NewMember.BPLNo = 0;

But, Visual Studio 2005 is giving warning that variables with type
'int' cannot be 'null'. How to check this?

I also want to know is there any functions like IsNumeric, IsString
etc. in C#.

No need to check, because int can not be null.

int? can be null if you need the capability.

Arne
if(NewMember.BPLNo.GetType()==typeof(String)
...
if(NewMember.BPLNo.GetType().IsValueType) or IsClass etc ..
...

Colin =^.^=
Nov 12 '07 #3
Cif(NewMember.BPLNo.GetType().IsValueType) or IsClass etc ..

If you start down the reflection road you need to be very careful;
int? (Nullable<int>) is a value-type, and is nullable depending on
your definition of nullable. Also you'd need to watch for the BPLNo
being null - but in general, the reflection approach is only needed if
you don't know what your data is - either because of "object", or
perhaps because of generics. In the case of a property this seems
overkill. Especially for an int property where there is no real
question of nullability.

Marc

Nov 12 '07 #4

"RP" <rp*********@gmail.comwrote in message
news:11**********************@e34g2000pro.googlegr oups.com...
>I have a member variable of a class of type "int", and while assigning
value to it in a constructor, I want to check whether it is a null. I
am using following code:
All memory is zero-filled before the constructor runs, this means that
references become "null" and numeric variables become zero.
>
if (NewMember.BPLNo == null)
NewMember.BPLNo = 0;

But, Visual Studio 2005 is giving warning that variables with type
'int' cannot be 'null'. How to check this?

I also want to know is there any functions like IsNumeric, IsString
etc. in C#.
Perhaps you want the TryParse function of int/long/float/double/decimal for
validation of strings that are supposed to be numbers?
Nov 12 '07 #5

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

Similar topics

1
by: Martin | last post by:
Hello Everybody! I have a POLINE table on a SQL Server 2000 DB. Before I update the record I need to check that either field, STORELOC or WONUM has data on it. If both fields are NULL I would...
2
by: Doug Baroter | last post by:
Hi, DDLs and DMLs: create table #job (jobID int identity(1,1) primary key, jobName varchar(25) unique not null, jobEndDate dateTime, jobComplete bit default(0), check (( is null and = 0) OR (...
4
by: Laphan | last post by:
Hi all In my functions I'm using a double-check all the time to trap if a value has nothing in it and my question is do I need this double-check. My check line is: IF IsNull(xxx) OR...
3
by: GS | last post by:
Hi, I have following value which I need to check wether it's null or not. Issue is that StartPrice itself can be a null and checking (myItem.StartPrice.Value == null) do not produce true. How do...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
1
by: shapper | last post by:
Hello, I have 3 different properties in a class. The properties are of types: Mail.MailPriority, Mail.MailAddress and Mail.MailAddressCollection I wan to check if the properties were...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
3
by: Helen Wheels | last post by:
Can we use parentheses in a check constraint in MS-SQL-server DDL? e.g. I'm having a problem with the following statement: ALTER TABLE . ADD CONSTRAINT CHECK (( IS NULL AND IS NULL) OR (...
14
by: Mark | last post by:
Hi, I would like to check if my object has been deleted or not, but my program keeps crashing. Here's the simplified code (in infinite loop) delete tetromino; //if(tetromino==NULL)...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.