Pass integer by reference : Function Parameters « Language Basics « C# / C Sharp






Pass integer by reference

 
using System;

public class Starter {

    public static void MethodA(ref int parameter) {
        parameter = parameter + 5;
    }

    public static void Main() {
        int var = 2;
        MethodA(ref var);
        Console.WriteLine(var); // 7
    }
}

 








Related examples in the same category

1.Reference, output and value parameters.
2.Passing parameters to methods
3.creates instances of a value and a reference type
4.Pass valuel by pointer
5.ref pointer parameter
6.Arrays as Function Returns and Parameters
7.Use ref to mark an object parameter
8.Use out to mark an object parameter