foreach到一个对象列表

时间:2013-02-10 10:58:28

标签: c# foreach

给定一个对象列表,我将它们保存到这样的文本文件中:

public void Save(PhoneBook pb)
{
   foreach (PhoneBookGroup item in pb.Items)
   {
        File.WriteAllText(path, item.GroupName + "@");
        foreach (Contect contect in item.Items)
       {
           File.WriteAllText(path, "Group :" + item.GroupName + "#"+
                                   "Name : " + contect.Name + "$" +
                                   "Number : " + contect.Number + "$" +
                                   "Addres : " + contect.Addres + "$");
       }
   }
} 

结果是:组:组Aaa#名称:Ziv $ Number:1 $ Addres:Sokolov $

现在我想在保留逻辑的同时从该文件加载并将每个组添加到列表中。使用char查找程序查找(对象名称为#,属性名称为$)示例:

Aaa(object)  
ziv(attributes)  
1(attributes)  
sokolov(attributes)

等等

bbb(object)  
jon(attributes)  
2(attributes)  
somewhere(attributes)   

public void Load()
{
   List<PhoneBook> phoneBookList = new List<PhoneBook>();

   string line = File.ReadAllText(path);
   foreach (var item in line)
   {

   }
   return phoneBookList;

}

0 个答案:

没有答案