【发布时间】:2011-02-25 13:12:13
【问题描述】:
我写了一些关于 ref -out 声明的代码块。我认为 ref 是最有用的。好的。为什么我需要用完。我每次都可以使用 always ref:
namespace out_ref
{
class Program
{
static void Main(string[] args)
{
sinifA sinif = new sinifA();
int test = 100;
sinif.MethodA(out test);
Console.WriteLine(test.ToString());
sinif.MethodB(ref test);
Console.WriteLine(test.ToString());
Console.ReadKey();
}
}
class sinifA
{
public void MethodA(out int a)
{
a = 200;
}
int _b;
public void MethodB(ref int b)
{
_b = b;
b = 2*b;
}
}
}
【问题讨论】:
标签: c# .net visual-studio visual-studio-2008 oop