• Top Posts

    When to use struct instead of class in C#


    • Consider defining a structure instead of a class if instances of the type are small and commonly short-lived or are commonly embedded in other objects.
    • Do not define a structure unless the type has all of the following characteristics:
    1. It logically represents a single value, similar to primitive types (integer, double, and so on).
    2. It has an instance size smaller than 16 bytes.
    3. It is immutable.
    4. It will not have to be boxed frequently.

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728