Review Questions

1:List three kinds of data abstractions where structs should be considered instead of classes.
2:Mention the important similarities and differences between classes and structs.
3:If myStruct is a value type, how is the following call possible if WriteLine only accepts reference types?
Console.WriteLine("Details of myStruct" + myStruct);
4:Can a struct have an explicit default constructor?
5:Why is boxing called boxing?
6:Suppose the struct Fraction contains the two public data members numerator and denominator. Fraction does not contain any explicitly defined constructors. You now write the following code:
Fraction myFraction;
myFraction.ToString();

Is the second line valid? Why or why not?

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.