ref pointer parameter : Function Parameters « Language Basics « C# / C Sharp






ref pointer parameter

 

using System;

public class Starter {

    public unsafe static void Main() {
        int val = 5;
        int* pA = &val;
        Console.WriteLine("Original: {0}", (int)pA);
        MethodA(pA);
        Console.WriteLine("MethodA:  {0}", (int)pA);
        MethodB(ref pA);
        Console.WriteLine("MethodB:  {0}", (int)pA);
    }

    public unsafe static void MethodA(int* pArg) {
        ++pArg;
    }

    public unsafe static void MethodB(ref int* pArg) {
        ++pArg;
    }

}

 








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.Arrays as Function Returns and Parameters
6.Use ref to mark an object parameter
7.Use out to mark an object parameter
8.Pass integer by reference