Skip to main content
 首页 » 编程设计

c#之无法从文本框传递变量

2024年02月13日11zhoujg

在线

const string subject = "hello" + textBox1.Text; 

它不打印 textBox1.Text 的值,但我打印了“textBox1.Text”这个词。我该如何解决?

var fromAddress = new MailAddress("samuimark@gmail.com", "samui mail"); 
var toAddress = new MailAddress("teeramail@gmail.com", "To Name"); 
const string fromPassword = "t429"; 
const string subject = "hello" + textBox1.Text  ; 
const string body = "you have a mail"; 
 
var smtp = new SmtpClient 
{ 
    Host = "smtp.gmail.com", 
    Port = 587, 
    EnableSsl = true, 
    DeliveryMethod = SmtpDeliveryMethod.Network, 
    UseDefaultCredentials = false, 
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword) 
}; 
using (var message = new MailMessage(fromAddress, toAddress) 
{ 
    Subject = subject, 
    Body = body 
}) 
{ 
    smtp.Send(message); 
} 

请您参考如下方法:

代替

const string subject = "hello" + textBox1.Text  ; 

使用

string subject = "hello" + textBox1.Text;