Other features C #

1. nullable type: represents plus a null value within the normal range of values ​​of type

  (1) Structure: nullable type is an instance of a generic structure Nullable <T>, which is declared as: public struct Nullable <T> where T:? Struct, grammar T is Nullable <T> is shorthand for both forms They are equivalent:

           Nullable<int> myNullableInt = new Nullable<int>(),等价于int ? myNullableInt = null;

  (2) may include the following types of empty instance members:

    1) .HasValue: read-only attribute, determines whether the value, if the current value is not empty, returns true, false otherwise

    2) .Value: read-only attribute, if the current value is non-empty, can be a normal visit, or description Value does not contain a meaningful value, will throw an exception InvalidOperationException At this time access Value

    3) .GetValueOrDefault (): method of example, if the current value is non-empty (the HasValue as to true), the return value Vlaue otherwise returns the default value of type T (which is the default value of the private field)

    4) .GetValueOrDefault (T defaultValue): example method, if the current value is non-empty (the HasValue as to false), to return Vlaue value, otherwise the default value defaultValue

Guess you like

Origin www.cnblogs.com/zwj-199306231519/p/11688616.html