编译器错误 CS0646
更新:2007 年 11 月
错误消息
不能对包含索引器的类型指定 DefaultMember 属性
如果类或其他类型指定了 System.Reflection.DefaultMemberAttribute,则不能包含索引器。有关更多信息,请参见属性。
下面的示例生成 CS0646:
// CS0646.cs
// compile with: /target:library
[System.Reflection.DefaultMemberAttribute("x")] // CS0646
class MyClass
{
public int this[int index] // an indexer
{
get
{
return 0;
}
}
public int x = 0;
}
// OK
[System.Reflection.DefaultMemberAttribute("x")]
class MyClass2
{
public int prop
{
get
{
return 0;
}
}
public int x = 0;
}
class MyClass3
{
public int this[int index] // an indexer
{
get
{
return 0;
}
}
public int x = 0;
}