在C#中,ref的意思是按引用传递.可以参考C++: int a = 10, b = 20; void swap(int x, int y) { int temp = x; x = y; y = temp; } 如果简单的调用这个swap,比如:swap(a, b),那么你根本没办法交换这两个变量的值,因为x和y都是形参,在swap返回的时候,x和y都被释放了.但如果是这样定义swap: void swap (int& x, int& y) { int temp = x; x = y; y…
我们可能见到下面的代码 public static void StringBuilderNoRef(StringBuilder s) { s.Append(" World"); s = new StringBuilder("hi"); } public static void StringBuilderRef(ref StringBuilder s) { s.Append(" World"); s = new StringBuil…
Java关键字及其作用 一. 关键字总览 访问控制 private protected public 类,方法和变量修饰符 abstract class extends final implements interface native new static strictfp synchronized transient volatile 程序控制 break continue return do while if else for instanceo…