我一直在尝试编写一个可以扫描原始数据文件并将其规范化以进行数据挖掘过程的程序,我试图从文件中读取数据并将其存储在列表中:
public static List<Normalize> NF()
{
//Regex r = new Regex(@"^\d+$");
List<Normalize> N = new List<Normalize>();
StreamReader ss = new StreamReader(@"C:\Users\User\Desktop\NN.txt");
String Line = null;
while (!ss.EndOfStream) {
Line = ss.ReadLine();
var L = Line.Split(',').ToList();
N.Add(new Normalize { age = Convert.ToInt16(L[0]),
Sex = L[1],
T3 = Convert.ToDouble(L[2]),
TT4 = Convert.ToDouble(L[3]),
TFU = Convert.ToDouble(L[4]),
FTI = Convert.ToDouble(L[5]),
RC = L[6],
R = L[7]
});
}
return N;
}
}
struct Normalize {
public int age;
public String Sex;
public double T3;
public double TT4;
public double TFU;
public double FTI;
public String RC;
public String R;
}
此时我想浏览我制作的列表并对数据进行分类,类似于:
var X= NF();
for (int i = 0; i < X.Count; i++) {
if (X[i].age > 0 && X[i].age <= 5) { // Change the X[i].age value to 1 }
else if (X[i].age > 5 && X[i].age <= 10) { // Change the X[i].age value to 2 }
...
}
但是编译器说 X[i].[variable name] 不是变量,不能以这种方式修改。我的问题是,执行此操作的有效方法是什么。