文件内容
[DEFAULT]
NICKNAME=Mu3Seagate
FIRSTNAME=wang
LASTNAME=123456
SINGILECONNECTION=1
[HP]
NICKNAME=HP
FIRSTNAME= 123456
LASTNAME= 52631
SINGILECONNECTION=1
[RMA189]
NICKNAME=RMA
FIRSTNAME=5891
LASTNAME=5555555
SINGILECONNECTION=1
List<string> list = new List<string>(); list = File.ReadAllLines(@"C:\Windows\Eado.ini").ToList().Where(x => !string.IsNullOrEmpty(x)).ToList(); List<string> listdns = new List<string>(); //0,5,10 List<string> listNICKNAME = new List<string>(); //1,6,11 List<string> listFIRSTNAME = new List<string>(); //2,7,12 List<string> listLASTNAME = new List<string>(); //3,8,13 List<string> listSINGILECONNECTION = new List<string>(); //4,9,14 for (int i = 0; i < list.Count; i++)//等差数列算法 { if (i % 5 == 0) listdns.Add(list[i].Replace("[","").Replace("]","").Trim()); else if (i % 5 == 1) listNICKNAME.Add(list[i].Replace("NICKNAME", "").Replace("=", "").Trim()); else if (i % 5 == 2) listFIRSTNAME.Add(list[i].Replace("FIRSTNAME", "").Replace("=", "").Trim()); else if (i % 5 == 3) listLASTNAME.Add(list[i].Replace("LASTNAME", "").Replace("=", "").Trim()); else if (i % 5 == 4) listSINGILECONNECTION.Add(list[i].Replace("SINGILECONNECTION", "").Replace("=", "").Trim()); } List<FileModel> listFile = new List<FileModel>(); for (int i = 0; i < listdns.Count; i++) { listFile.Add(new FileModel() { dns = listdns[i],NICKNAME =listNICKNAME[i],FIRSTNAME=listNICKNAME[i], LASTNAME=listLASTNAME[i], SINGILECONNECTION =listSINGILECONNECTION[i] }); } return listFile.Where(x => x.dns.ToUpper().Equals("DEFAULT")).ToList().FirstOrDefault().NICKNAME;