Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int[] test = { 1, 2, 3, 4 };

            modifContenuSansRef(test);
            Console.WriteLine(test[0]); // OK --> 99 array is reference type

            //By default, all parameters are passed by value in C#.
            //Parameters are only passed by reference if you explicitly include an out or ref modifier.
            //However, you need to be aware that when the type of the parameter is a reference type,
            //you're passing a reference rather than an actual object
            modifTailleSansRef(test);
            Console.WriteLine(test.Length); // KO --> 4 La taille n'est pas modifiée


            Apple a = new Apple();

            Console.WriteLine(a.num);
            changeApple(a);
            Console.WriteLine(a.num);
        }
Exemplo n.º 2
0
 static void changeApple(Apple a)
 {
     //pass by value, another stack var also points to the same heap area
     a.num = 20;
 }