};
Example
This sample shows how you can use DefaultMemberAttribute to specify the default indexer.
[cpp] // specify_default_indexer.cpp
// compile with: /LD /clr
using namespace System;
[Reflection::DefaultMember("XXX")]
public ref struct Squares {
property Double XXX[Double] {
Double get(Double data) {
return data*data;
}
}
};
// specify_default_indexer.cpp
// compile with: /LD /clr
using namespace System;
[Reflection::DefaultMember("XXX")]
public ref struct Squares {
property Double XXX[Double] {
Double get(Double data) {
return data*data;
}
}
};
Example
This sample consumes the metadata created in the previous example.
[cpp] // consume_default_indexer.cpp
// compile with: /clr
#using "specify_default_indexer.dll"
int main() {
Squares ^ square = gcnew Squares();
System::Console::WriteLine("{0}", square[3]);
}
// consume_default_indexer.cpp
// compile with: /clr
#using "specify_default_indexer.dll"
int main() {
Squares ^ square = gcnew Squares();
System::Console::WriteLine("{0}", square[3]);
}
Output
摘自 xufei96的专栏