ref
タイプとReference type
私はオブジェクトの値を変更することができるので、それらの違いは何ですか?C#の参照型とrefの違いは何ですか?
誰かがanswerを提供しましたが、それでも私にとっては不明です。 ref
キーワードと
static void Main(string[] args)
{
myclass o1 = new myclass(4,5);
Console.WriteLine("value of i={0} and j={1}", o1.i, o1.j); //o/p=4,5
o1.exaple(ref o1.i, ref o1.j); //Ref type calling
Console.WriteLine("value of i={0} and j={1}", o1.i, o1.j);// o/p=2,3
myclass o2 = o1;
Console.WriteLine("value of i={0} and j={1}", o2.i, o2.j); // o/p 2,3
o1.i = 100;
o1.j = 200;
Console.WriteLine("value of i={0} and j={1}", o1.i, o1.j); //o/p=100,200
Console.WriteLine("value of i={0} and j={1}", o2.i, o2.j); //o/p=100,200
Console.ReadKey();
}
public class myclass
{
public int i;
public int j;
public myclass(int x,int y)
{
i = x;
j = y;
}
public void exaple(ref int a,ref int b) //ref type
{
a = 2;
b = 3;
}
}
それはポインタとCのポインタへのポインタの違いです。 –