I am passing a String Array to a function with the code below. The strings in the array are the first part of email addresses. I need to add domain.com to the end of each string and a "," between each address. I have working code below, but just wondering if there is a (better/cleaner/efficient) way of doing this?
String toAddress = "";
for (int x = 0; x < addresses.Length; x++)
{
if (x == (addresses.Length-1))
{
toAddress += addresses[x] + "@domain.com";
}
else
{
toAddress += addresses[x] + "@domain.com,";
}
}
You could use Join
and Linq Select
to solve this
string toAddress = string.Join(",", addresses.Select(x => x + "@domain.com"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With