using linq


string strPerilName;

 foreach (CoverCode poliyccode in Latest.CoverCodes)
                    foreach (Peril item in poliyccode.Perils)
                        strPerilName += item.Peril.Name + ",";                      


how do i do the above code using linq
Who is Participating?
Bob LearnedConnect With a Mentor Commented:
If CoverCodes is a List<T>, then you can use this (using StringBuilder):

var perilName = new StringBuilder();

Latest.CoverCodes.ForEach(x => perilName.Append(x.Peril.Name + ","));

var output = perilName.ToString().TrimEnd(',');

Open in new window

praveen1981Author Commented:
Many thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.