#776 – Declaring and Using Nullable structs
February 8, 2013 2 Comments
You can make any value type nullable, allowing it to either be null or to contain one of its normal values.
Since user-defined structs are value types, you can also make any struct nullable, using Nullable<T> or T? notation.
// Regular struct GuyInfo gi1 = new GuyInfo("Isaac", 1642); // Nullable, with no value Nullable<GuyInfo> gi2 = null; // Nullable, 2nd form, with value GuyInfo? gi3 = new GuyInfo("Albert", 1879); bool hasVal1 = gi2.HasValue; bool hasVal2 = gi3.HasValue;
Pingback: Dew Drop – February 8, 2013 (#1,496) | Alvin Ashcraft's Morning Dew
Pingback: Interesting .NET Links – February 11 , 2013 | TechBlog