Exercise
Function Double Reference Parameter
Objective
Write a C# function named "Double" to calculate the double of an integer number, and modify the data passed as an argument. It must be a "void" function and you must use "refererence parameters". For example.
x = 5;
Double(ref x);
Console.Write(x);
would display 10
Write Your C# Exercise
C# Exercise Example
// Importing the System namespace to access basic system functions
using System;
class Program
{
// Function to calculate and modify the number passed as a reference parameter
public static void Double(ref int number)
{
// Multiply the input number by 2 to double it
number = number * 2;
}
// Main method where the Double function is called
public static void Main()
{
// Initialize the integer variable x
int x = 5;
// Call the Double function with x passed by reference
Double(ref x);
// Display the modified value of x (doubled)
Console.Write(x);
}
}