public class Lesson2_MethodsAndArguments

{

void Methods()

{

So far, everything we’ve been doing has been in the Main method. However, one of the features of good code writing is that methods are kept small and organized. One method may call another, and another, and another, with each one achieving a specific task.

}
 

void AccessModifiers()

{

If meant to be accessible by another class (file), the method declaration should begin with the public modifier. The default access level is private which means the method can only be called from within the same class.

}
 

void Static()

{

Static is a more advanced concept, yet it is always used in the Program class for any methods called via Main. Static means that the method belongs to the Type of the class, not to a particular object instantiation. We will return to it at a later point.

}
 

void MethodName()

{

The method name can be anything, but it is good to make it a clear description of what the method does. Method names cannot have spaces or special characters, so most .NET programmers use either PascalCase (capitalize every word) or camelCase (capitalize every word except the first).

}
 

void ParametersAndArguments()

{

When creating a method, you can pass variables to it by way of parameters listed in parentheses. When calling the method, these same variables are referred to as arguments.

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *