Chapter 4. Methods and Parameters

From what you have learned about C# programming so far, you should be able to write structured programs that are similar to programs created in the 1970s. Obviously, programming has come a long way since the 1970s, and the next major programming paradigm was structured programming. Structured programming provides a construct into which statements are grouped together to form a unit. Furthermore, with structured programming, it is possible to pass data to a group of statements and then have data returned once the statements have executed.

This chapter covers how to group statements together into a method. In addition, it covers how to call a method, including how to pass data to a method and receive data from a method.

Besides the basics of calling and defining methods, this chapter also covers some slightly more advanced conceptsnamely, recursion and method overloading. All method calls discussed so far and through the end of this chapter are static (a concept which Chapter 5 explores in detail).

Even as early as the HelloWorld program in Chapter 1, you learned how to define a method. In that example, you defined the Main() method. In this chapter, you will learn about method creation in more detail, including the special C# syntax for parameters that pass data to and from a method (ref) using a single parameter, as well as parameters that only pass data out from a method (out). Lastly, I will touch on some rudimentary error handling.

Essential C# 2.0
Essential C# 2.0
ISBN: 0321150775
EAN: 2147483647
Year: 2007
Pages: 185 © 2008-2017.
If you may any questions please contact us: