Declare And Use Methods

Methods are members of an object or class that implement a computation or action. You can use methods to hold a section of code that may be used more than one time. Methods are built into classes using method declarations.

Many objects in the .NET Framework classes contain useful methods. For example, the .NET Framework DateTime class has several methods that can be used, such as the ToLongDateString method, which converts a Date or DateTime to a long version of a Date (for example: Thursday, May 30, 2002).

Programmers also use methods to encapsulate functionality. For example, you could represent a printer as an object. One of the methods could be PrintPage. This method could take in a parameter that is a stream of data to be printed and could return a value that indicates whether the data printed successfully. Consider a Calculator object as another example. This object could have several methods like Add, Subtract, Multiply, and Divide. The Subtract method could take in two parameters that are integer data types and return an integer. The Subtract method would contain functionality that would take one parameter and subtract the other parameter and return the result.

DECLARE AND USE METHODS

% Untitled - Notepad

DECLARE AND USE METHODS

% Untitled - Notepad

Square Tubing Radius Chart

D Open your text editor.

^0 Type using System; to import the System namespace and press Enter.

< Type the name of the class you want to create and press Enter.

0 Between the curly braces, create the Main function.

—0 Declare a string variable to hold the date, and a character variable to hold the user input.

□ Write a message about the types of formats to the console.

D Open your text editor.

^0 Type using System; to import the System namespace and press Enter.

< Type the name of the class you want to create and press Enter.

Q Type { }, placing the opening and closing curly braces on separate lines, to set off the body of the class.

0 Between the curly braces, create the Main function.

—0 Declare a string variable to hold the date, and a character variable to hold the user input.

□ Write a message about the types of formats to the console.

Was this article helpful?

0 0

Post a comment