I'm really new to C# so this may seem like a novice question..How does C# accomplished passing a reference to a object reference? I'm really trying to understand the underlying mechanisms and how it applies to the attached code with the comments - //what happens here? Do we pass a ref->ref->ref....or is this accomplished via reference counting.
using System;
class my_int{
int itsx;
int itsy;
public my_int(int x, int y){
itsx = x;
itsy = y;
}
public void display_it(){
Console.WriteLine("x->{0}, y->{1}", itsx, itsy);
}
}
namespace testit
{
class MainClass{
static void myfunc(ref my_int m, int x){
if ( x < 10 )
myfunc(ref m, ++x);//what happens here? Do we pass a ref->ref->ref....or is this accomplished via reference counting.
else
m = new my_int(888, 999);
}
static void Main(string [] args){
my_int me = new my_int(123, 456);//create a reference 'me' to a my_int object
me.display_it();
myfunc(ref me, 0);//pass a reference to the reference 'me'.
me.display_it();
}
}
}