3

I have a method for parsing 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
}

I want to parse XML file and then get node out of parsed list with specific CurrentID. I want to return ProperID list but compiler errores out with:

Cannot implicitly convert type 'Classes.XMLprofile.Profile' to 'System.Collections.Generic.List<Classes.XMLprofile.Profile>'

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Tagyoureit
  • 359
  • 1
  • 5
  • 18
  • 1
    1.spelling of `Resoults` 2. update line ` var ProperID = Resoults.Where(s => s.CurrentID <= 10).Aggregate((c, d) => c.CurrentID > d.CurrentID ? c : d).ToList();` and try – J Santosh Sep 03 '15 at 04:15

1 Answers1

5

You want return Results that have proper id in CurrentId, In code you got compiler error because of return value is a Profile object and method signature is a List of Profile objects, So:

return Resoults.Where(p=>p.CurrentID ==ProperID.CurrentID).ToList();
Reza ArabQaeni
  • 4,848
  • 27
  • 46