Difference between revisions of "Parameter Passing - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 4: Line 4:
 
  int a = 10;
 
  int a = 10;
 
  string b= "yes";
 
  string b= "yes";
 +
 
or otherwise.
 
or otherwise.
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
From Simulation:
 +
<syntaxhighlight lang="csharp">
 +
if (menuOption == 4)
 +
        {
 +
          x = InputCoordinate('x');
 +
          y = InputCoordinate('y');
 +
        ...
 +
        }
 +
    private int InputCoordinate(char Coordinatename)
 +
    {
 +
      int Coordinate;
 +
      Console.Write("  Input " + Coordinatename + " coordinate: ");
 +
      Coordinate = Convert.ToInt32(Console.ReadLine());
 +
      return Coordinate;
 +
 +
</syntaxhighlight>
 +
The method InputCoordinate declares x and y as int, the chars 'x' and 'y' are passed into InputCoordinate to use.

Revision as of 15:38, 13 February 2017

Parameter passing is inserting values into methods or calculations using a declared variable, rather than the raw data (strings, numbers, bools, etc.). This can be done in multiple ways, but the most often used (in the skeleton program) will be:

 int a = 10;
 string b= "yes";

or otherwise.

From Simulation:

 if (menuOption == 4)
        {
          x = InputCoordinate('x');
          y = InputCoordinate('y');
        ...
        }
    private int InputCoordinate(char Coordinatename)
    {
      int Coordinate;
      Console.Write("  Input " + Coordinatename + " coordinate: ");
      Coordinate = Convert.ToInt32(Console.ReadLine());
      return Coordinate;

The method InputCoordinate declares x and y as int, the chars 'x' and 'y' are passed into InputCoordinate to use.