• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

convert arrayList to string

I need to convert an arrayList to a string so I can pass the parameter into my method that requires a string parameter:

ArrayList repEmailList = RepresentationDAO.GetEmailList(anAddress.StateAbr);
//foreach (string emailAddress in repEmailList)

SendMail.Send(repEmailList, "info@compasslearning.com", "CompassLearning Sales Information Request", strmsg);

repEmailList needs to be converted to a string

Thanks for any help.
0
-Dman100-
Asked:
-Dman100-
  • 3
  • 3
1 Solution
 
Expert1701Commented:
Do you want to send one email to all the recipients?

  string addresses = "";
  foreach(string emailAddress in repEmailList)
    addresses += (emailAddress=="" ? "" : ";") + emailAddress;

  SendMail.Send(addresses, ...
0
 
-Dman100-Software ConsultantAuthor Commented:
yes, I'm only sending one email to all recpients.
0
 
Expert1701Commented:
And I made a mistake in my code, it should have been:

  string addresses = "";
  foreach(string emailAddress in repEmailList)
    addresses += (addresses=="" ? "" : ";") + emailAddress;

  SendMail.Send(addresses...

But that should do it!
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
-Dman100-Software ConsultantAuthor Commented:
If I may ask, what is this line doing:  addresses += (emailAddress=="" ? "" : ";") + emailAddress;
0
 
Expert1701Commented:
the correct one is,

  addresses += (addresses=="" ? "" : ";") + emailAddress;

It checks to see if this is the first email address and if not, includes a semicolon before adding it.  It is so you do not have an extra ';' either at the start or the end of your string.
0
 
-Dman100-Software ConsultantAuthor Commented:
Thanks for your help!  It works great!

Regards,
-D-
0
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.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now