The following code gives me an error:
Match the best overloaded method for the system. Xml.Linq.XElement.XElement (System.Xml.Linq.XName, Object) has some invalid arguments.
What do I need to change, from which I can iterate my list & lt; Customers & gt; Creating XDocument with the ring with the collection?
using system; Using System.Collections.Generic; Using System.Xml.Linq; Namespace test_xml3 {class program {static zero main (string [] args) {list & lt; Customers & gt; Customers = new list & lt; Customers & gt; New customer {first name = "gym", last name = "smith", age = 27}, new customer {first name = "hank", last name = "moore", age = 28}, new customer {first name = "j" LastName = "Smythe", age = 44}}; Console.WriteLine (BuildXmlWithLINQ (customers)); Console.ReadLine (); } Private Static String BuildXmlWithLINQ (list & customer; customer & gt; clients) {XDocument xdoc = New XDocument (New XDeclaration ("1.0", "utf-8", "Yes"), New XElement ("Customer" Clients. ForEach (c = New XElement ("Customer", New XElement ("First Name", C. First Name), New XElement ("Last Name", C. Listen))); xdoc.Declaration.ToString () Return to Environment + NewLine + xdoc .Storing ();}} Public class customer {public string first name {get; set;} public string LastName {get; set;} public id {get; set;}}} Add Gone:
Thank you for all your replies, I also came along with it which works:
Private static string BuildXmlWithLINQ2 (list & lt; customer & gt; clients XDocument xdoc = New XDocument (New XDeclaration ("1.0", "utf-8", "Yes")) ("Customer", New Excellence ("First Name", Customer First Name), New Excellence ("Last Name", Customer.Lostname), New Exileme T ( "Age", the customer. Edge)); XRoot.Add (XElement); } Return xdoc.Declaration.ToString () + environment. NewLine + xdoc.ToString (); }
You customers.ForEach to customer . Configure all .
Comments
Post a Comment