Articles → .NET → Comma Separated String Using LINQ

Comma Separated String Using LINQ









<root>
    <country>India</country>
    <country>Sri Lanka</country>
    <country>Australia</country>
</root>






DataSet ds = new DataSet();
ds.ReadXml(@"C:\Users\guptak\Desktop\CommaSep\CommaSep\XMLFile1.xml");
string str = string.Join(",", (from element in ds.Tables[0].AsEnumerable() select element["country_text"].ToString()).ToArray());
MessageBox.Show(str);








Picture showing the output of how to convert the table into the comma separated list using LINQ
Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Thursday, December 23, 2010

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250