C# ref and out
2007-04-03 13:56
387 查看
pass parameters with reference:
ref and out same:
both the method definition and the calling method must explicitly use the ref keyword.
both the method definition and the calling method must explicitly use the out keyword
static void Method(out int i, out string s1, out string s2)
{
i = 44;
s1 = "I've been returned";
s2 = null;
}
static void Main()
{
int value;
string str1, str2;
Method(out value, out str1, out str2);
// value is now 44
// str1 is now "I've been returned"
// str2 is (still) null;
}
Different:
An argument passed to a ref parameter must first be initialized. This differs from out, whose argument need not be explicitly initialized before being passed.
ref and out same:
both the method definition and the calling method must explicitly use the ref keyword.
both the method definition and the calling method must explicitly use the out keyword
static void Method(out int i, out string s1, out string s2)
{
i = 44;
s1 = "I've been returned";
s2 = null;
}
static void Main()
{
int value;
string str1, str2;
Method(out value, out str1, out str2);
// value is now 44
// str1 is now "I've been returned"
// str2 is (still) null;
}
Different:
An argument passed to a ref parameter must first be initialized. This differs from out, whose argument need not be explicitly initialized before being passed.
相关文章推荐
- DEMO[C#]refKeyword and outKeyword 关于ref与out关键字区别的DEMO
- DEMO[C#]refKeyword and outKeyword 关于ref与out关键字区别的DEMO
- Understanding ref And out With C# 7
- C# : ref out params and override
- C#中使用ref和out一点认识!
- C#:ref和out的联系及区别。
- C# 使用 ref 和 out 传递数组
- C#:ref和out的联系及区别
- 深入理解C#之 参数传递 ref out params
- C#中按引用传递与按值传递的区别,以及ref与out关键字的用法详解
- C#中的 ref 和 out
- C# ref、out、params与值类型参数修饰符
- 【原创】C#中ref和out的异同
- c#中out和ref的使用级区别
- C#中ref和out参数使用时需要注意的问题
- C#之ref与out
- C#中out和ref的区别
- 浅析c#中ref和out、as和is使用的异同
- 5.C#知识点:ref和Out关键字浅谈
- c#基础系列3---深入理解ref 和out