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 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.