为什么以下两个代码示例产生不同的输出?
情况1
enum EnumType
{
First,
Second,
Third
}
class ClassB
{
public string Func(int index)
{
return "Func(int)";
}
public string Func(EnumType type)
{
return "Func(EnumType)";
}
}
class Program
{
static void Main(string[] args)
{
ClassB b = new ClassB();
Console.WriteLine(b.Func(0));
Console.WriteLine(b.Func(EnumType.First));
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
Func(int)
Func(EnumType)
Run Code Online (Sandbox Code Playgroud)
案例2
enum EnumType
{
First,
Second,
Third
}
class ClassA
{
public string Func(int index)
{
return "Func(int)";
}
}
class ClassB : ClassA
{
public string Func(EnumType enumType)
{ …Run Code Online (Sandbox Code Playgroud) 这对我来说有点冗长:
ostrstream ss;
ss << "Selected elements: " << i << "," << j << ".";
string msg(ss.str(), (size_t)ss.pcount());
Run Code Online (Sandbox Code Playgroud)
是否有一种优雅的方法来使用简洁的单行语句(可能带有模板或宏)来格式化文本消息?