gpt4 book ai didi

c# - 在覆盖基本方法时,为什么默认参数不能正常工作?

转载 作者:行者123 更新时间:2023-11-30 12:12:09 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
C# optional parameters on overridden methods

using System;
namespace Apple
{
class A
{
public virtual void Func(int a=4){
Console.WriteLine(" A Class: "+a);
}
}
class B : A
{
public override void Func(int a = 12)
{
Console.WriteLine(" B Class: "+ a);
}
}

public class Program
{
static void Main(string[] args)
{
A ob = new B();
ob.Func();
Console.ReadLine();
}
}
}
// Output: B Class: 4

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com