The ? character that indicates a nullable type is really a shortcut to the System.Nullable<T> structure, where T is the type being made nullable. In other words, using int? is equivalent to using System.Nullable<System.Int32>.
You can make any value type nullable using the Nullable<T> syntax. You’d typically do this for your own customstruct or enum types.
For example, assume that you have the following two custom types.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| // How I'm feelingpublic enum Mood{ Crabby, Happy, Petulant, Elated}// A 3D point with a namepublic struct Point3D{ public float X, Y, Z; public string Name;} |
You can use these types as nullable types using Nullable<T>.
1
2
3
4
| Nullable<Mood> me = Mood.Crabby;me = null;Nullable<Point3D> nonPoint = null; |

