Question

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

MailMessage mailmessage = new MailMessage();
string mailFrom;
mailFrom = "PropertyLossForm";
mailmessage.From = new MailAddress("propertyloss@brixmor.com", 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.

Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top