Purpose:
I want to implement a hard-coded lookup table for data that often does not change, but when they change, I want to be able to quickly update the program and rebuild.
Plan:
My plan was to define a custom data type, for example ...
private class ScalingData
{
public float mAmount;
public String mPurpose;
public int mPriority;
ScalingData(float fAmount, String strPurpose, int iPriority)
{
mAmount = fAmount;
mPurpose = strPurpose;
mPriority = iPriority;
}
}
and then in the main class hard set the array this way ...
public static ScalingData[] ScalingDataArray =
{
{1.01f, "Data point 1", 1},
{1.55f, "Data point 2", 2}
};
However, this is not being built. I continue to see the message " ". Type mismatch: cannot convert from float[] to ScalingData
How can I achieve my goal?
UPDATE
I tried to implement the proposals so far, but still ran into an error ...
The code looks like this:
public class CustomConverter
{
private static ScalingData[] ScalingDataArray =
{
new ScalingData(1.01f, "Data point 1", 1),
new ScalingData(1.55f, "Data point 2", 2)
};
CustomConverter()
{
}
private class ScalingData
{
public float mAmount;
public String mPurpose;
public int mPriority;
ScalingData(float fAmount, String strPurpose, int iPriority)
{
mAmount = fAmount;
mPurpose = strPurpose;
mPriority = iPriority;
}
}
}
and an error with a hard-coded array
No enclosing instance of type CustomConverter is accessible.
Must qualify the allocation with an enclosing instance of type CustomConverter
(e.g. x.new A() where x is an instance of CustomConverter).
EDIT ... complete solution in accordance with the answers below
public class CustomConverter
{
private static ScalingData[] ScalingDataArray =
{
new ScalingData(1.01f, "Data point 1", 1),
new ScalingData(1.55f, "Data point 2", 2)
};
CustomConverter()
{
}
private static class ScalingData
{
public float mAmount;
public String mPurpose;
public int mPriority;
ScalingData(float fAmount, String strPurpose, int iPriority)
{
mAmount = fAmount;
mPurpose = strPurpose;
mPriority = iPriority;
}
}
}