我在尝试重载新的 .NET 6 C# 控制台应用程序模板(顶级语句)Print(object)中的函数时遇到错误。
void Print(object obj) => Print(obj, ConsoleColor.White);
void Print(object obj, ConsoleColor color)
{
Console.ForegroundColor = color;
Console.WriteLine(obj);
Console.ResetColor();
}
Run Code Online (Sandbox Code Playgroud)
错误是:
Print(obj, ConsoleColor.White)->No overload for method Print() that takes 2 argumentsPrint(object obj, ConsoleColor color)->A local variable or function named 'Print' is already defined in this scope我尝试改变他们的顺序,但仍然抛出错误。这是怎么回事?