5

Possible Duplicate:
What does “DateTime?” mean in C#?
What does the ? mean after a type?

I had a function declaration including a questionmark after the datatype like:

private TimeSpan? sometime()
{

}

What does this mean?

Community
  • 1
  • 1
CloudyMarble
  • 36,156
  • 70
  • 93
  • 127

5 Answers5

16

TimeSpan? is shorthand for System.Nullable<TimeSpan>.

A TimeSpan is a value type, which cannot take a null value. By wrapping it in a System.Nullable<> it can be null. Without that ? it would be illegal to return null from the function.

Anders Abel
  • 66,163
  • 17
  • 148
  • 213
4

Nullable Structure

Represents an object whose underlying type is a value type that can also be assigned null like a reference type.

Instead of writing Nullable<TimeSpan>, you can write TimeSpan?.

CD..
  • 68,981
  • 24
  • 147
  • 156
2

Nullable, that a value type can be null.

Devin Burke
  • 13,392
  • 11
  • 53
  • 80
Per Kastman
  • 4,361
  • 22
  • 21
1

It means that the value type is a nullable type

T23
  • 572
  • 2
  • 11
1

Basically its a nullable TimeStamp.

BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
detheridge02
  • 640
  • 1
  • 6
  • 18