Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is stored in a variable that has null value?

Status
Not open for further replies.

sheila11

Programmer
Dec 27, 2000
251
US
Hi all,

C# now has nullables.

If I have declared a nullable variable, and its value is null, then what is stored in it?

int? x;

I was asked this question in an interview, and I am puzzled.

TIA,
Sheila

 
I wouldn't say c# 'now' has nullables, they have been there since 2.0 (2004/2005)

[tt]int?[/tt] is shorthand for [tt]Nullable<int>[/tt] so I would say the value is a nullable object of type int. for all practical purposes there are 3 possible values:
the default (0)
a non-default (not 0)
null

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
To answer the OP's question: I'd say null. The HasValue property will be false if the value is null, but there's still a memory location with a value stored in it, and the value is null.
 
Oo,that came out kinda wrong. I didn't mean to suggest that nobody else answered the question! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top