我有一个函数:
private myfunction(ref object obj)
{
}
我在其他地方调用
int a=0;
myfunction(ref a);
为什么编译通不过?

解决方案 »

  1.   

    object a=0;
    myfunction(ref a);int b=(int)a;
      

  2.   

    不要这样做。
    想编译通过很容易int a = 0;
    object b = (object)a;
    myfunction(ref b);但是b是a装箱后的,你传递进去b,如果要使用,还要拆箱,你不能在调用后
    a = (int)b;
    得到返回结果。你需要看看“泛型”
    这样声明方法:
    private static void myfunction<T>(ref T obj)
    {
    }这样使用,就可以了。
    int a = 0;
    myfunction<int>(ref a);