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

Explain the '?' in: int? a = null;

I'm learning c# and see a code example where a value of null is assigned to
a variable:

int? a = null;

I could not find this in the docs. can someone please explain exactly what
the '?' is? and where-all it can be used?

Thanks.
--
mo*******@nospam.nospam
Mar 2 '06 #1
4 1455
You should search for "nullable types" in documentation.

In short this allow value types to have null assigned to them. It is a
shorthand for creating a variable of the generic System.Nullable<T>
structure type.

-José
"moondaddy" <mo*******@nospam.nospam> wrote in message
news:Ok**************@TK2MSFTNGP14.phx.gbl...
I'm learning c# and see a code example where a value of null is assigned to a variable:

int? a = null;

I could not find this in the docs. can someone please explain exactly what the '?' is? and where-all it can be used?

Thanks.
--
mo*******@nospam.nospam

Mar 2 '06 #2
Hi moondaddy,

The question mark means that variable is a nullable type. Nullable types
represent value-type variables that can be assigned the value of null. You
cannot create a nullable type based on a reference type. (Reference types
already support the null value.)

You can check the following link for more information:

http://msdn2.microsoft.com/en-us/library/1t3y8s4s.aspx

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Mar 2 '06 #3
moondaddy wrote:
I'm learning c# and see a code example where a value of null is assigned to
a variable:

int? a = null;

I could not find this in the docs. can someone please explain exactly what
the '?' is? and where-all it can be used?


It's a new feature in C# 2.0. See
http://www.pobox.com/~skeet/csharp/c.../nullable.html for more
information.

Jon

Mar 2 '06 #4
Thanks to all that replied. This helps and the links were good too!

--
mo*******@nospam.nospam
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
moondaddy wrote:
I'm learning c# and see a code example where a value of null is assigned
to
a variable:

int? a = null;

I could not find this in the docs. can someone please explain exactly
what
the '?' is? and where-all it can be used?


It's a new feature in C# 2.0. See
http://www.pobox.com/~skeet/csharp/c.../nullable.html for more
information.

Jon

Mar 2 '06 #5

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

Similar topics

0
by: developer | last post by:
I have the following query that takes anywhere from 1 to 3 seconds to run. I would expect it to run in less than 1/2 a second (and I really need it to do so). I've added the appropriate indices...
13
by: C++fan | last post by:
The following code is for list operation. But I can not understand. Could anyone explain the code for me? /* * List definitions. */ #define LIST_HEAD(name, type) struct name { type...
3
by: Jan Nielsen | last post by:
Hi I am working with rowfilters in dataviews. I would like to filter for empty fields (= null value in the database) I found this sentence on msdn: **************** To return only those columns...
5
by: Jon Lapham | last post by:
I have been using the EXPLAIN ANALYZE command to debug some performance bottlenecks in my database. In doing so, I have found an oddity (to me anyway). The "19ms" total runtime reported below...
11
by: Faisal Vali | last post by:
Hi - I'm new to javascript and I was reading the book Javascript Professional Projects - there is a fragment that has me a little perplexed, and I was wondering if anyone could explain why and how...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.