110,526
社区成员
发帖
与我相关
我的任务
分享
private List<MacData> getMacData(String txtPath) {
List<MacData> strMaclist = new List<MacData>();
// String Spath = txtPath;
//int rowNumber = 1;
// StreamReader sr = new StreamReader(Spath);
// String strLine = sr.ReadLine().Trim();
String sn = String.Empty;
using (StreamReader sr = new StreamReader(txtPath)) {
String line;
while ((line = sr.ReadLine().Trim()) != "") {
String[] tempArr;
tempArr = line.Split(' ');
for (int i = 0; i < tempArr.Length; i++) {
if (tempArr[i] == "Number") {
sn = tempArr[i+1];
continue;
}
if (tempArr[i] == "is") {
for (int j = i+1; j < tempArr.Length; j++) {
MacData macdata = new MacData();
if (tempArr[i] != null) {
macdata.SerialNumber = sn;
macdata.Mac = Hexadecimal(tempArr[j]);
strMaclist.Add(macdata);
}
}
}
}
// line = sr.ReadLine().Trim();
// rowNumber++;
}
// return strMaclist;
}
return strMaclist;
}
求解為什麽會報錯 private List<MacData> getMacData() {
List<MacData> strMaclist = new List<MacData>();
String Spath = "C:\\Users\\Administrator\\Desktop\\1.txt";
int rowNumber = 1;
StreamReader sr = new StreamReader(Spath);
String strLine = sr.ReadLine();
String sn = String.Empty;
while (!String.IsNullOrEmpty(strLine)) {
String[] tempArr;
tempArr = strLine.Split(' ');
for (int i = 0; i <= tempArr.Length; i++) {
MacData macdata = new MacData();
if (tempArr[i] == "Number") {
sn = tempArr[i + 1];
}
if (tempArr[i] == "is")
{
for (int j = i+1; j < tempArr.Length;j++ ) {
macdata.SerialNumber = sn;
macdata.Mac = tempArr[j];
strMaclist.Add(macdata);
}
break;
}
}
strLine = sr.ReadLine();
rowNumber++;
}
return strMaclist;
}
為什麽對應的MAC都是一樣的