I have a loop in my app. Code is following :-
foreach (DataRow dr in dt.Rows)
ColorNames +=dr["ColorName"].ToString() + "\n";
But i don’t want to add \n at the last Datarow. Any suggestion how to do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Foreach do not work on index.
Option 1: ForEach Loop
Use foreach loop. Loop till last and outside loop do like
Option 2: For Loop
Use for loop and check for index inside loop for all indexes till last. add \n and in last index do not add \n
OR
Option 3: LINQ