O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required