Creating Methods

The next step in coding is to divide your code into methods. Methods are members of classes that hold code and can be called to execute that code. We've already seen how to write and work with the Main method, so this idea should be somewhat familiar. Here's how you declare a method in C#:

[attributes] [modifiers] type identifier ([[out][ref]
type parameter, [[out][ref]type parameter, ...]]) statement
				

Here are the parts of this declaration:

  • attributes (Optional)— Hold additional declarative information, as we'll see in Chapter 14, “Using Attributes and Reflection.”

  • modifiers (Optional)— The allowed modifiers are new, static, virtual, abstract, override, and a valid combination of the four access modifiers we'll see in the ...

Get Microsoft® Visual C#® .NET 2003 Kick Start now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.