gpt4 book ai didi

c# - 如何用重载和覆盖方法来解释这种行为?

转载 作者:可可西里 更新时间:2023-11-01 03:09:48 25 4
gpt4 key购买 nike

<分区>

谁能如此友善并向我解释为什么此代码显示 Derived.DoWork(double)。我可以对这种行为提出一些解释,但我希望有人为我澄清这一点。

using System;

public class Base
{
public virtual void DoWork(int param) {
Console.WriteLine("Base.DoWork");
}
}

public class Derived : Base
{
public override void DoWork(int param) {
Console.WriteLine("Derived.DoWork(int)");
}

public void DoWork(double param) {
Console.WriteLine("Derived.DoWork(double)");
}

public static void Main() {
int val = 5;
Derived d = new Derived();
d.DoWork(val);
}
}

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