我有一个问题,每个Enum类型都应与一个静态列表相关联。
我尝试执行以Enum为集合的for-each循环,但是我的编译器在抱怨。
// Used to select a material
public Enum MaterialList{
Concrete = 0,
Wood = 1,
}
// Used to populate and allow user to adjust material coefficient values on a curve
public class MaterialEditor {
public static List<int> materialFrequencies;
public static List<float> reflCoefficient;
public void refreshCurve() {
materialFrequencies = AcousticMaterialBuffer.readXMLfreqMat(matName);
reflCoefficient = AcousticMaterialBuffer.readXMLreflMat(matName);
PopulateCurve(myReflCurve);
}
public void PopulateCurve(Curve reflectionCurve){
...
for(int i = 0; i < materialFrequencies.Count; i++) {
reflectionCurve.AddKey(materialFrequencies[i]);
reflectionCurve.AddKey(reflCoefficient[i]);
...
}
}
}
// Used to store material values from an XML file into List<float>()
public class AcousticMaterialBuffer {
public static List<int> ReadXMLfreqMat(string MaterialName){
List<int> matFreq = new List<int>();
- ..Load an XML file and add elements to matFreq..
return matFreq;
}
public static List<float> ReadXMLreflMat(string MaterialName){
List<float> matRefl = new List<float>();
- ..Load an XML file and add elements to matRefl..
return matRefl;
}
}
当选择“材质X”时,在所有引用“材质X”的对象上的值应保持一致,并且当您更改“材质X”的任何值时,它们对于所有其他对象都应自动更改。物料Y和Z也是如此。
当前,当我从“材质X”更改为“材质Y”时,即使它们引用了“材质X”,它也会将所有其他对象材质值更改为“材质Y”。我意识到这是因为调用了refreshCurve(),它会更改所有其他对象,因为它们从一个静态列表中获取值。
如何为每种枚举类型创建新的静态列表?