在函数中不改变参数的值,用普通传递还是ref传递哪种效率高??因为在函数中不改变参数的值,C#跟c++一样吗 传地址没有副本`效率要高 所以用ref效率要高吗??还是??

解决方案 »

  1.   

    看传的是什么。如果是大size的类就用ref,普通的用val
    像我要处理几M的文本文件时就是用ref,调用函数才七八次时间差了好几倍。
      

  2.   

    请教一下:
    对于大size的类,基本上是reference type,也就是说,这样的一个变量实际上是一个引用。
    如果是这样,用不用ref在性能上好像没什么区别?下面是一本书上抄来的:
    In C#, all parameters are passed by value unless we specifically say otherwise. However, we need to be careful in understanding the implications of this for reference types. Since reference type variables only hold a reference to an object, it is this reference that will be copied, not the object itself.