正在加载图片...
泛型方法 间提题 交换两个int数的方法 I/交换两个double数的方法 static void Swap(ref int x,ref int y) static void Swap(ref double x,ref double y) { int temp; double temp; temp x; temp =x; x=y; x=y; y temp; y=temp; 型 川交换任意两个数的方法 static void Swap <T>(ref T x,ref T y) int a=1; int b=2; T temp; Swap <int>(ref a,ref b); 调用 temp x; doublec=1.1; x=y; double d 2.2; y temp; Swap<double>(ref c,ref d); 1111 泛型方法 //交换两个int数的方法 static void Swap(ref int x, ref int y) { int temp; temp = x; x = y; y = temp; } //交换两个double数的方法 static void Swap(ref double x, ref double y) { double temp; temp = x; x = y; y = temp; } //交换任意两个数的方法 static void Swap <T> (ref T x, ref T y) { T temp; temp = x; x = y; y = temp; } 泛 型 int a = 1; int b = 2; Swap <int> (ref a,ref b); double c = 1.1; double d = 2.2; Swap<double> (ref c, ref d); 调用
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有