'attribute' : 屬性只允許出現在類別索引子 (預設索引的屬性) 上
備註
設計成套用至類別索引子屬性 (property) 的屬性 (attribute) 的使用方式錯誤。
如需詳細資訊,請參閱 如何:在 C++/CLI 中使用屬性。
範例
下列範例會產生 C3459。
// C3459.cpp
// compile with: /clr /c
public ref class MyString {
public:
[System::Runtime::CompilerServices::IndexerName("Chars")] // C3459
property int Prop;
};
// OK
public ref class MyString2 {
array<int>^ MyArr;
public:
MyString2() {
MyArr = gcnew array<int>(5);
}
[System::Runtime::CompilerServices::IndexerName("Chars")] // OK
property int default[int] {
int get(int index) {
return MyArr[index];
}
void set(int index, int value) {
MyArr[index] = value;
}
}
};