MailAddress.ToString 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回此实例的字符串表示形式。
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
返回
String,包含此 MailAddress 的内容。
示例
下面的代码示例显示电子邮件的目标。
static void CreateTestMessage4( String^ server )
{
MailAddress^ from = gcnew MailAddress( L"ben@contoso.com" );
MailAddress^ to = gcnew MailAddress( L"Jane@contoso.com" );
MailMessage^ message = gcnew MailMessage( from,to );
message->Subject = L"Using the SmtpClient class.";
message->Body = L"Using this feature, you can send an email message from an application very easily.";
SmtpClient^ client = gcnew SmtpClient( server );
Console::WriteLine( L"Sending an email message to {0} by using SMTP host {1} port {2}.", to, client->Host, client->Port );
client->Send( message );
client->~SmtpClient();
}
public static void CreateTestMessage4(string server)
{
MailAddress from = new MailAddress("ben@contoso.com");
MailAddress to = new MailAddress("Jane@contoso.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an email message from an application very easily.";
SmtpClient client = new SmtpClient(server);
Console.WriteLine("Sending an email message to {0} by using SMTP host {1} port {2}.",
to.ToString(), client.Host, client.Port);
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateTestMessage4(): {0}",
ex.ToString());
}
}
注解
此方法返回的字符串不一定与创建实例时指定的字符串相同。 如果 属性 DisplayName 不 null
等于 String.Empty (“”) , ToString 则返回使用以下语法组成的字符串:
如果 DisplayName 为 null
或 等于 String.Empty, ToString 则返回 属性的值 Address 。