Parameters - Global Variables

From TRCCompSci - AQA Computer Science
Revision as of 17:46, 16 December 2016 by C3ypt1c (talk | contribs) (Image changed to code.)
Jump to: navigation, search

When a variable needs to be passed into a subroutine, this is done through the use of parameters. The subroutine can then use these parameters to execute its code. Parameters should be written inside the subroutine brackets, along with their variable type. In addition, multiple parameters should be separated by commas (",").

Example

 1 namespace Project
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             greeting("Geoff");
 8             greeting("Bob");
 9         }
10 
11         static void greeting(string name)
12         {
13             Console.WriteLine("Hello, " + name);
14         }
15     }
16 }
17 //Output:
18 //Hello, Geoff
19 //Hello, Bob