Pergunta

Hi I have my project in 4 days and I got code from http://www.youtube.com/watch?feature=player_embedded&v=mGDnQchFZJg#! , I could really use help, thanks in advance.

jet it gives me an error in foreach loop 

Error 1 The name 's' does not exist in the current context

        MailMessage poruka = new MailMessage();
        poruka.From = new MailAddress(textBox4.Text);
        poruka.Subject = textBox2.Text;
        poruka.Body = textBox3.Text;
        foreach (string s in textBox1.Text.Split()) ;
        poruka.To.Add(s);


        SmtpClient client = new SmtpClient();
        client.Credentials = new NetworkCredential(textBox4.Text, textBox5.Text);
        client.Host = "smtp.yahoo.com";
        client.Port = 587;
        client.EnableSsl = true;
        client.Send(poruka);
Foi útil?

Solução

You have a ; at the end of your foreach, which means s is not in the scope when you add it to poruka. Change it to be like this:

foreach (string s in textBox1.Text.Split())
{
    poruka.To.Add(s);
}

This is the reason I, personally, always like to use braces and not inline my foreach's.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top