Prev article
Newer
Next article
Older
Unwrapping examples:
// a wrapped value int? val = 10; // unwrapping (five different ways) int i1 = (int)val; // Returns val.Value or throws a System.InvalidOperationException int i2 = val.Value; // Returns val.Value or throws a System.InvalidOperationException int i3 = val.GetValueOrDefault(); // Returns val.Value or zero int i4 = val.GetValueOrDefault(-1); // Returns val.Value or -1 int i5 = val ?? -1; // Returns val.Value or -1
See also:
Ads by Google
© Richard McGrath