I’m wondering what ? means in C# ?
I’m seeing things like: DateTime? or int?. I suppose this is specific to C# 4.0?
I can’t look for it in Google because I don’t know the name of this thing.
The problem is I’m using DateTime and I have a lot of cast errors (from DateTime to DateTime?).
Thank you
It’s a shorthand for writing
Nullable<int>orNullable<DateTime>. Nullables are used with value types that cannot be null (they always have a value).It is not specific to C#4 by the way.
You can only assign an
int?to anintif it has a value, so your code would have to do things like:Also note that a
Nullablehas two properties,HasValueandValuethat you can use test if a value has been set and to get the actual value.