MailAddress.ToString メソッド

定義

このインスタンスの文字列形式を返します。

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、("") ToString と等String.Emptyしくない場合は、次の構文を使用して構成された文字列を返します。

DisplayName <User@Host>

null または と等しい ToStringString.Empty場合DisplayNameは、 プロパティの値をAddress返します。

適用対象