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 get and set accessors that are used to retrieve and modify a member field, respectively. The set accessor has an implicit parameter named value that 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 ref or the out keyword.

  • The out parameter 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 ...

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.