无法访问电子邮件地址数组中的元素

时间:2013-12-11 17:52:52

标签: c# arrays mailmessage

以下是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));
}

它告诉我mailmessage.To.Add(mailToArray(i)); mailArray被用作方法。不知道该怎么做。

1 个答案:

答案 0 :(得分:2)

首先,您需要将Array mailToArray =更改为string[] mailToArray

mailmessage.To.Add(mailToArray (i) );应为mailmessage.To.Add(mailToArray [i] );,索引器为阵列。标识符旁边的()用于表示方法,而[]用于“索引到”数组并获取特定元素。虽然它是一个普通的运算符并且被覆盖,但理论上它甚至可以被视为一种方法(不要这样做。)