【发布时间】:2013-03-08 00:15:39
【问题描述】:
我可以在 C# 中声明两个不同类型但名称相似的属性吗? 像这样的:
public class Types
{
public string Element
{
get { return ""; }
}
public int Element
{
get { return 0; }
}
}
【问题讨论】:
-
不,你不能那样做。你为什么不自己尝试一下?!
-
编译器告诉你什么?这些名字不相似,它们是相同的
-
您是否尝试过实际编译您的代码。你会比在 SO...上提问更快得到答案。
-
请用正确的术语,从你的例子来看,你的意思是
With the same name而不是With similar name。 -
可能会建议如何做这样的事情?
标签: c# properties