完全没有看懂!
1、ref out 关键字
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Person
{
public string Name
{
get;
set;
}
public string Age
{
get;
set;
}
}
class Program
{
static void Test( Person p)
{
p.Name = "one";
p.Age = "2";
}
static void Test1(ref Person p)
{
p = new Person();
p.Name = "two";
p.Age = "123";
}
static void Test2(out Person p)
{
p = new Person();
p.Name = "dou";
p.Age = "11525";
}
static void Main(string[] args)
{
Person p = new Person();
p.Name = "lowe";
p.Age = "123";
Console.WriteLine("{0},{1}",p.Name,p.Age);
Test(p);
Console.WriteLine("{0},{1}", p.Name, p.Age);
Test1(ref p);
Console.WriteLine("{0},{1}", p.Name, p.Age);
Test2(out p);
Console.WriteLine("{0},{1}", p.Name, p.Age);
}
}
}

本文通过具体的C#代码示例,详细解释了ref和out关键字的使用方法及其区别。通过对比不同调用方式下对象的变化,展示了这两个关键字如何影响参数传递。
441

被折叠的 条评论
为什么被折叠?



