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 。