Chapter 8: Inside Methods

Quiz Solutions

Solution to Question 8-1. Method overloading allows the author of the class to create a method with varying input parameters, rather than having to have many methods with different names that serve similar purposes.

Solution to Question 8-2. Overloaded methods must differ in the number of parameters, the parameter types, or both. Simply differing in return type is not an overload.

Solution to Question 8-3. The signature of a method is its name and the types on its parameter list.

Solution to Question 8-4. Properties are public accessors to your encapsulated data. Properties appear to the class creator as methods, but to the class’s clients as fields.

Solution to Question 8-5. Properties enforce encapsulation through data hiding. They isolate the internal members of the class from the client. If you change how the internal values are generated, the property will seem to be unchanged, to outside callers.

Solution to Question 8-6. To create a read-only property, do not implement the set part of the property. No special notation is required.

Solution to Question 8-7. Automatic properties provide a shorter way for you to create a property, if all you need to do is set or retrieve a value.

Solution to Question 8-8. You retrieve multiple return values from a method by passing in parameters by reference and getting the results back in those parameters.

Solution to Question 8-9. If you want to pass a value object (variable) by reference, you use the keyword ...

Get Learning C# 3.0 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.