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,908
  • 70
  • 97
  • 130

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
  • 67,989
  • 17
  • 150
  • 217
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..
  • 72,281
  • 25
  • 154
  • 163
2

Nullable, that a value type can be null.

Devin Burke
  • 13,642
  • 12
  • 55
  • 82
Per Kastman
  • 4,466
  • 24
  • 21
1

It means that the value type is a nullable type

T23
  • 582
  • 2
  • 11
1

Basically its a nullable TimeStamp.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
detheridge02
  • 640
  • 1
  • 6
  • 18