很简单的问题,因为C#里没有引用了,所以我想知道对于基本类型,我怎么才能实现传引用。
比如这样一个函数
void test(int j)
{
    j++;
}
int j = 9;
test(j);
int i = j;//i = 10.
我希望在调用test函数之后,j的值就已经改变了,请问应该怎么做?

解决方案 »

  1.   

    private void Swap( ref int i; ref int j ) 
    {
      int tmp = i;
      i = j;
      j = tmp;
    }private void test() 
    {
      int a = 10;
      int b = 20;
      Swav( ref a, ref b );}
      

  2.   

    void test(ref int j)
    {
        j++;
    }
    int j = 9;
    test(ref j);
      

  3.   

    不知道static变量行不行,可以试下
      

  4.   

    谁说C#没有引用了?void test(ref int j)
    {
        j++;
    }int j = 9;
    test(ref j);
    int i = j;//i = 10没有问题啊
      

  5.   

    void test(ref int j)
    {
    }
    test(ref j);