關於重載問題
using System;
public class temp
{
public void Test(ref int x)
{
x++;
}
public void Test(out int x)
{
x=100;
}
public void Test(int x)
{
x++;
}
public static void Main()
{
int x;
Test t=new Test();
t.Test(out x);
t.Test(ref x);
t.Test(x);
Console.WriteLine(x);
}
}
編譯結果:25.cs(9,15): error CS0663: 'Test' 無法定義只有 ref 與 out 區別的多載方法
25.cs(5,15): (與之前錯誤相關符號的位置)
請問為什麼會出現這種問題。
问题点数:0、回复次数:3Top
1 楼hertcloud(·£孙子兵法£·)回复于 2004-04-03 13:07:29 得分 0
我想 可能是vs 中 ref 合out的定义 问题吧
Top
2 楼jjyang1704(crystal5)回复于 2004-04-03 13:25:23 得分 0
我沒有vs,我是用csc編譯的Top
3 楼Ninputer(装配脑袋)回复于 2004-04-03 13:57:02 得分 0
重载的时候不能仅仅通过ref和out不同来区别两个方法。ref和out本质上都是传递引用,只有C#才区分他们,为的是让代码更清晰。Top




