C Sharp

Methods

As you learned in tutorial 1, "Fundamentals of Object-Oriented Programming," classes are encapsulated bundles of data and the methods that work on that data. Put another way, methods give classes their behavioral characteristics, and we name methods after the actions we want the classes to carry out on our behalf.

So far, I haven't gotten into the more specific issues regarding defining and calling methods in C#. That's where this tutorial comes in—you'll discover the ref and out method parameter keywords and how they enable you to define a method such that it can return more than a single value to the caller.

You'll also learn how to define overloaded methods so that multiple methods with the same name can function differently depending on the types and/or number of arguments passed to them. Then you'll learn how to handle situations in which you don't know the exact number of arguments a method will have until run time. Finally, I'll wrap up the tutorial with a discussion of virtual methods—which will build on the inheritance discussion in tutorial 5, "Classes"—and how to define static methods.