Would this be what you trying to do?
UserName_arr.Aggregate((x,y) => x + "<" + y);
You can check out more on Aggregate here.
Or you can do TrimEnd
in your code :
main_UserName = String.Join("<", UserName_arr);
main_UserName = main_UserName.TrimEnd('<');
String.Join
example :
string[] dinosaurs = new string[] { "Aeolosaurus",
"Deinonychus", "Jaxartosaurus", "Segnosaurus" };
string joinedString = string.Join(", ", dinosaurs);
Console.WriteLine(joinedString);
Output :
Aeolosaurus, Deinonychus, Jaxartosaurus, Segnosaurus
See there is no , in the end.
See String.Join
this example.
Edit :
Based on OP's comment and Vera rind's comments the problem OP faced was the wrong declaration of String array.
It had one element more than required, which resulted in being a Null
element in the end of the array.
This array when used with String.Join
due to the null last element resulted in an unwanted "<" at the end.
Either change your array declaration to :
string[] UserName_arr = new string[usercount];
Or check for null string in the Join condition :
String.Join("<", UserName_arr.Where(x => string.IsNullOrEmpty(x) == false))