按属性重新匹配对象列表

Tag*_*eit 3 c# list

我有一个解析方法XML:

public static List<Profile> Parse XML(string Document)
{
    List<Profile> Result = new List<Profile>();     
    doc = XDocument.Load(Document);

    Resoults = (from n in doc.Descendants("level")
               select new Profile()
               {
                   CurrentID = int.Parse(n.Attribute("CurrentID").Value),    
                   Location = (from l in n.Element("ID").Elements("ID")
                              select new Location()
                              {
                                   id = (int)(l.Attribute("id")),
                                   x = (Single)l.Attribute("x"),
                                   y = (Single)l.Attribute("y"),
                                   z = (Single)l.Attribute("z")
                              }).ToList(),    
                   Bank = (from l in doc.Descendants("Banker")
                              select new Banker()
                              {
                                   BankID = (int)(l.Attribute("id")),
                                   BankX = (Single)(l.Attribute("x")),
                                   BankY = (Single)(l.Attribute("y")),
                                   BankZ = (Single)(l.Attribute("z"))
                              }).ToList(),    
                   Vendor = (from l in doc.Descendants("Vendor")
                              select new Vendor()
                              {
                                   VendorID = (int)(l.Attribute("id")),
                                   VendorX = (Single)(l.Attribute("x")),
                                   VendorY = (Single)(l.Attribute("y")),
                                   VendorZ = (Single)(l.Attribute("z")) 
                              }).ToList()
              }).ToList();      
    var ProperID =  Resoults.Where(s => s.CurrentID <= 10).Aggregate((c, d) => c.CurrentID > d.CurrentID ? c : d);    
    return ProperID;  //error: Here i want to return list ProperID
}
Run Code Online (Sandbox Code Playgroud)

我想解析XML文件,然后从特定的解析列表中获取节点CurrentID.我想返回ProperID列表但编译errores出来:

无法隐式转换'Classes.XMLprofile.Profile''System.Collections.Generic.List<Classes.XMLprofile.Profile>'

Rez*_*eni 5

你想要返回在CurrentId中具有正确id的结果,在代码中由于返回值而导致编译器错误是Profile对象,而方法签名是Profile对象的List,所以:

return Resoults.Where(p=>p.CurrentID ==ProperID.CurrentID).ToList();
Run Code Online (Sandbox Code Playgroud)