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