Identifying the class/struct Relationship
Although classes and structs are both objects, they serve separate purposes and it's good to know when to use each. The primary differences between the two types are in the area of value versus reference types and in their inheritance properties. There are also a couple other differences that are presented in this chapter. Before racking and stacking the differences, let's look at exactly what a struct is and what it looks like, as shown in the following example.
public struct Person { string name; int height; int weight; public bool OverWeight() { // some theoretical calculation return false; } }
Perhaps the struct in this code belongs to an application for dieticians. The name, height, and weight ...
Get C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.