引用传参
csharp
using System;
public class Program
{
public static void Main()
{
Tools t = new Tools();
t.bf();
double a = 10;
double b = 20;
t.change(ref a, ref b);
Console.WriteLine(b);
}
}
class Tools {
public void af() {Console.Write("a\n");}
internal void bf() {Console.Write("b\n");}
public void change(ref double a, ref double b) {
dynamic t;
t = a;
a = b;
b = t;
}
}
调用方法时,你必须使用 ref 关键字:
csharp
t.change(ref a, ref b);
输出传参
csharp
using System;
namespace LHJ {
class TODO {
static void Main() {
Tools t = new Tools();
int a, b;
Console.WriteLine("add = {0}, doublea = {1}, double b = {2}",
t.foo(2, 3, out a, out b), a, b);
}
}
class Tools {
public int foo(int x, int y, out int a, out int b) {
a = x * 2;
b = y * 2;
return x + y;
}
}
}
csharp
public int foo(int x, int y, out int a, out int b)
此方法返回一个int
的foo
,和两个out
int
注意调用时要带out
csharp
t.foo(2, 3, out a, out b)