Summarizing custom type choices
Now that we have covered OOP and the C# features that enable you to define your own types, let's summarize what you've learned.
Categories of custom type and their capabilities
Categories of custom type and their capabilities are summarized in the following table:
Type | Instantiation | Inheritance | Equality | Memory |
class |
Yes | Single | Reference | Heap |
sealed class |
Yes | None | Reference | Heap |
abstract class |
No | Single | Reference | Heap |
record or record class |
Yes | Single | Value | Heap |
struct or record struct |
Yes | None | Value | Stack |
interface |
No | Multiple | Reference | Heap |
It is best to think about these differences by starting with the "normal" case and then spotting the differences in other cases. For example, a "normal" class
can be instantiated with new
, it supports single inheritance, it uses memory reference equality, and its state is stored in heap memory.Now let's highlight what is different about the more specialized types...