tags:

views:

237

answers:

6

I am reading an article about the MVVP Pattern and how to implement it with WPF. In the source code there are multiple lines where I cannot figure out what the question marks in it stand for.

private DateTime? _value;

What does the ? mean in the definition? I tried to find it in the help from VS but failed.

+5  A: 

That means the type is Nullable.

Anvaka
+12  A: 

It's a nullable value. Structs, by default, cannot be nullable, they must have a value, so in C# 2.0, the Nullable<T> type was introduced to the .NET Framework.

C# implements the Nullable<T> type with a piece of syntactic sugar, which places a question mark after the type name, thus making the previously non-nullable type, nullable.

David Morton
+1  A: 

It means that the field is a Nullable<DateTime>, i.e. a DateTime that can be null

Thomas Levesque
+3  A: 

This is a nullable type, you can assign null to it

Svetlozar Angelov
More specifically it is a nullable value type.
Brian Rasmussen
+2  A: 

Private DateTime? _value - means that the _value is nullable. check out this link for a better explanation.

http://davidhayden.com/blog/dave/archive/2005/05/23/1047.aspx

Hope this helps.

Thanks, Raja

Raja
+3  A: 

cannot be null

DateTime                        
DateTime dt = null;   // Error: Cannot convert null to 'System.DateTime'
                         because it is a  non-nullable value type 

can be null

DateTime? / Nullable<DateTime>  
DateTime? dt = null;  // no problems
Asad Butt