Listing 3
using namespace System;
public ref class EngineeringData
{
/*1*/ static initonly array<double>^ coefficients;
/*2*/ static EngineeringData()
{
int elementCount;
// figure out how big array should be
// elementCount = ...
coefficients = gcnew array<double>(elementCount);
for (int i = 0; i < elementCount; ++i)
{
// coefficients[i] = ...
}
}
public:
/*3*/ static property double Coeff[int] {
double get(int index) { return coefficients[index]; }
}
};
int main()
{ double d;
try {
/*4*/ d = EngineeringData::Coeff[2];
}
catch (IndexOutOfRangeException^ ex)
{
// handle exception
}
}