Many of requirement's wants to convert list of string to a coma separated or any other format . We all are mostly followed Looping through & get it. Here is the simple example for doing that.
For Converting a list string to string
For Converting A list of classes We can use the below snippet.
Happy Doing...:)
For Converting a list string to string
List<string> lststr = new
List<string>();
lststr.Add("Hello") ;
lststr.Add("good");
lststr.Add("Morning");
string concate
= string.Join<string>(",", lststr);
For Converting A list of classes We can use the below snippet.
class Data
{
public int ID { get; set; }
public string Name { get; set; }
}
List<Data> ldata = new List<Data>();
Data dt=new Data();
dt.ID=1;
dt.Name="San";
ldata.Add(dt);
dt=new Data();
dt.ID=2;
dt.Name="Kumar";
ldata.Add(dt);
string FullName = string.Join<string>(",",
ldata.Select(x => x.Name));
Happy Doing...:)
No comments:
Post a Comment