小编Dav*_*yan的帖子

为什么输出默认值来自Base类?

为什么输出B5,有人可以解释吗?

class A
{
       public virtual void M(int x=5)
       Console.Write("A"+x);
}

class B:A
{
       public override void M(int x=6)
       Console.Write("B"+x);

}
class Program
{
       static void Main(string[] args)
        {
            A a = new B();
            a.M();
        }
}
//Output is : B5
Run Code Online (Sandbox Code Playgroud)

我希望输出为B6,但实际输出为B5。

.net c#

4
推荐指数
1
解决办法
61
查看次数

标签 统计

.net ×1

c# ×1