MailboxAddress Class

An email address and its display name, such as "Alice" <alice@example.com> ([RFC 5322] 3.4).

public sealed class MailboxAddress : IEquatable<MailboxAddress>
Implements

Constructors

NameDescription
MailboxAddress(string?, string)Initializes a new instance of the MailboxAddress class.

MailboxAddress(string?, string)

MailboxAddress.cs

Initializes a new instance of the MailboxAddress class.

public MailboxAddress(string? name, string address)

Parameters

name string?
The display name, or null.
address string
The address, such as alice@example.com.

Properties

NameDescription
AddressGets the address.
NameGets the display name, or null.

Gets the address.

public string Address { get; }

Property value

string

Gets the display name, or null.

public string? Name { get; }

Property value

string?

Methods

NameDescription
Equals(MailboxAddress?)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Determines whether the specified object is equal to the current object.
FormatList(IEnumerable<MailboxAddress>)Formats a list of addresses as the value of a header, with the display names encoded when they are not ASCII.
GetHashCode()Serves as the default hash function.
Parse(string?)Parses an address.
ParseList(string?)Parses a list of addresses, such as the value of a To header. The groups are flattened, and invalid entries are skipped.
ToHeaderValue()Returns the address as the value of a header: the display name, encoded when it is not ASCII, and the address.
ToString()Returns the display name and the address.

Equals overloads

Equals(MailboxAddress?)

MailboxAddress.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(MailboxAddress? other)
Parameters
other MailboxAddress?
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

MailboxAddress.cs

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current object.
Returns

bool true if the specified object is equal to the current object; otherwise, false.

FormatList(IEnumerable<MailboxAddress>)

MailboxAddress.cs

Formats a list of addresses as the value of a header, with the display names encoded when they are not ASCII.

public static string FormatList(IEnumerable<MailboxAddress> addresses)

Parameters

addresses IEnumerable<MailboxAddress>
The addresses.

Returns

string The value of the header.

GetHashCode()

MailboxAddress.cs

Serves as the default hash function.

public override int GetHashCode()

Returns

int A hash code for the current object.

Parse(string?)

MailboxAddress.cs

Parses an address.

public static MailboxAddress? Parse(string? value)

Parameters

value string?
The value.

Returns

MailboxAddress? The address, or null when the value has none.

ParseList(string?)

MailboxAddress.cs

Parses a list of addresses, such as the value of a To header. The groups are flattened, and invalid entries are skipped.

public static IReadOnlyList<MailboxAddress> ParseList(string? value)

Parameters

value string?
The value, with its encoded words.

Returns

IReadOnlyList<MailboxAddress> The addresses.

ToHeaderValue()

MailboxAddress.cs

Returns the address as the value of a header: the display name, encoded when it is not ASCII, and the address.

public string ToHeaderValue()

Returns

string The value of the header.

Returns the display name and the address.

public override string ToString()

Returns

string The display name and the address.