C# Value Types

  1. Value types derive from System.ValueType, which derives from System.Object.
  2. No separate heap allocations or garbage collection overhead.
  3. They are two types struct and enum
  4. Value types are sealed that means we cannot inherit directly from built in types
    although we can implement interfaces.
  5. Enum contains a set of named integral constants.
  6. Enum are derived from System.Enum which are derived from System.ValueType
  7. Reference types are class, interfaces and delegates. They are managed via heap management
    and have special garbage collection methodologies.
  8. Reference types fully supports inheritances
  9. Literal Types: We can specify how a numeric literal should be typed by appending
    a letter to the end of the number. For example, to specify that the value 4.56 should
    be treated as a float, append an “f” or “F” after the number: 4.56f. If no letter
    is appended, the compiler will infer a type for the literal.
  10. Generic Types: Types that have another type as parameters.
  11. Ordinary value types cannot have a value of null. However, you can create nullable
    value types by affixing a ? after the type. For example, int? is an int type that
    can also have the value null.
  12. Implicit types: Types declared by the keyword var
  13. Anonymous type: Anonymous types provide a convenient way to encapsulate a set of
    read-only properties into a single object without having to first explicitly define
    a type. The type name is generated by the compiler and is not available at the source
    code level. The type of the properties is inferred by the compiler. The following
    example shows an anonymous type being initialized with two properties called Amount
    and Message.

    var v = new { Amount = 108, Message = “Hello” };

  14. Nullable Types: Types that can contain null values. For example types declared with
    the format int?

Leave a Reply

Your email address will not be published. Required fields are marked *