How do I assign null to an integer?

  • Thread starter susan.fitzpatrick
  • Start date
S

susan.fitzpatrick

In C# integers are automatically intialized to zero. I need to assign
null to an integer (i.e. int i = null).

I cannot use Nullable Types because that is a feature in .NET 2.0 and I
need to use .NET 1.1.

Thanks
 
B

Bruce Wood

In C# integers are automatically intialized to zero. I need to assign
null to an integer (i.e. int i = null).

I cannot use Nullable Types because that is a feature in .NET 2.0 and I
need to use .NET 1.1.

You can't.

You must either:

1. Choose a value in the integer value range that you know your program
will never use, and assign it the meaning, "null":

const int NullCustomerId = -1;
int customerId = NullCustomerId;

or

2. Create a separate bool variable that will tell you whether the value
is null:

int customerId;
bool customerIdIsNull;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top