Chapter 36 User-Defined Subprograms

36.1 Subprograms that Return a Value

In many computer languages, a subprogram that returns a value is called a function. C# calls them methods and there are two categories of methods. There are the built-in methods, such as Math.Abs(), Math.Sqrt(), and there are the user-defined methods, those that you can personally write and use in your own programs.

The general form of a C# method that returns a value is shown here.

return_type name([type1 arg1, type2 arg2, type3 arg3, …]) {
Local variables declaration section
 
A statement or block of statements
return value;
}

where

return_type is the data type of the value that the method returns.
name is the name of the method.
arg1, arg2, arg3, … is a list of arguments ...

Get C# and Algorithmic Thinking for the Complete Beginner 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.