您的位置:首页 > 编程语言 > C#

【c#语法】占位符, out, ref

2015-06-02 12:14 204 查看

占位符

//使用占位符,显示顺序是按照占位符
Console.WriteLine("The first is {0}, second is {1}, third is {2}", a, b, c);
//不使用占位符显示
Console.WriteLine("The first is " + a + " second is " + b + " third is " + c);
Console.ReadKey();


out

有多个返回值得时候可以使用out关键字

public static void change(out int a, out int b, out int c) {
a=10;
b=20;
c=30;
}

int a ;
int b ;
int c ;
change(out a, out b, out c);//a=10, b=20,c=30


ref

ref关键字其实就是引用传递,,传递变量本身

//交换函数
public static void swap(ref int a, ref int b) {
int temp = a;
a= b;
b=temp;
}

int a=1;
int b =2;
swap(ref a, ref b);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: