Chapter 18

Answers to Chapter 18 Review Questions

1: List three kinds of data abstractions where structs should be considered instead of classes.
A1:
  1. To represent fractions (with a numerator and a denominator

  2. To represent points on a map (2D) or points in space (3D)

  3. To represent a time span

2: Mention the important similarities and differences between classes and structs.
A2: Similarities: structs and classes can both contain methods, properties, indexers, constructors, data members, operator methods, nested types; both can implement interfaces; and they both implicitly inherit from the System.Object class.

Differences: Structs cannot contain destructors; their constructors work in a slightly different way. Structs form value types, whereas classes ...

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.