Cannot Access Element in Array of Emails Addresses

124 views Asked by At

Here is my code for the Message.To.Add:

MailMessage mailmessage = new MailMessage();
string mailFrom;
mailFrom = "PropertyLossForm";
mailmessage.From = new MailAddress("[email protected]", mailFrom);

string mailTo;
mailTo = txtEmailAddress.Text;
mailTo = Strings.Replace(mailTo, ",", "");

//Separates the received string into and array of email addresses
Array mailToArray = null;
mailToArray = Strings.Split(Strings.Trim(mailTo), " ");

//Adds all of the recipients to the MailMessage
for (int i = mailToArray.GetLowerBound(0); i <= mailToArray.GetUpperBound(0); i++)
{
    //Response.Write(mailToArray(i) + "<br>")
    mailmessage.To.Add(mailToArray(i));
}

It's telling me mailmessage.To.Add(mailToArray(i)); mailArray is being used as a method. Not sure what to do.

1

There are 1 answers

5
Rob G On BEST ANSWER

First you need to change Array mailToArray = to string[] mailToArray.

mailmessage.To.Add(mailToArray(i)); should then be mailmessage.To.Add(mailToArray[i]); , the indexer for arrays. () next to an identifier are used to imply a method, while [] are used to 'index into' an array and grab a specific element. Though is a normal operator and be overridden, so theoretically it could even be treated as a method (don't do this.)