Summary
Overloading is the act of creating two or more methods with the same name, but that differ in the number, type of parameters, or both.
Properties appear to clients to be members, but appear to the designer of the class to be methods. This allows the designer to modify how the property retrieves its value without breaking the semantics of the client program.
Properties include
getandsetaccessors that are used to retrieve and modify a member field, respectively. Thesetaccessor has an implicit parameter namedvaluethat represents the value to be assigned through the property.Automatic properties provide a shorthand way of creating properties, if all you want to do is set or retrieve a value, as opposed to doing any other processing in the accessor.
When you “pass by reference,” the called method affects the object referred to in the calling method. When you pass by value, the changes in the called method are not reflected in the calling method. You can pass value types by reference by using either the
refor theoutkeyword.The
outparameter eliminates the requirement to initialize a variable before passing it to a method.
Now you have an idea of how methods work, and just how essential they are to your classes. Classes with no methods can still be very useful for holding data, but they won’t be able to do much on their own. You’ll be seeing methods extensively throughout the rest of this book, to the point where you probably won’t even think much about them anymore. You ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access