Custom Types

suggest change

Remarks

Typically a struct is used only when performance is very important. A struct is stored inline where it is declared: on the stack for a local variable, or inside the containing object on the heap. Copying a large struct is expensive, so structs should be kept small (Microsoft recommends that a struct take up no more than 16 bytes).

A class is the most-used type (of these three) in C#, and is generally what you should go with first.

An enum is used whenever you can have a clearly defined, distinct list of items that only need to be defined once (at compile time). Enums are helpful to programmers as a lightweight reference to some value: instead of defining a list of constant variables to compare to, you can use an enum, and get Intellisense support to make sure you don’t accidentally use a wrong value.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents