KeyValuePairHeaderValue Class

Namespace: System.Net.Http.Headers Assembly: System.Net.Http.Primitives

Represents a header value that consists of a name and a value.

Constructors

KeyValuePairHeaderValue(string name, string value)

Initializes a new instance of the KeyValuePairHeaderValue class.

public KeyValuePairHeaderValue(string name, string value)

KeyValuePairHeaderValue(string name)

Initializes a new instance of the KeyValuePairHeaderValue class.

public KeyValuePairHeaderValue(string name)

Properties

Name

Gets or sets the name of the header value.

public string Name { get; set; }

Value

Gets or sets the value of the header value.

public string Value { get; set; }

Methods

ToString()

Returns a string representation of the KeyValuePairHeaderValue object.

public override string ToString()

Equals(object obj)

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

public override bool Equals(object obj)

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Examples

Basic Usage

Creating and using a KeyValuePairHeaderValue:


using System.Net.Http.Headers;

// Create a KeyValuePairHeaderValue
var cookiePair = new KeyValuePairHeaderValue("sessionid", "12345abc");

// You can also create one with just a name
var customHeader = new KeyValuePairHeaderValue("X-Custom-Header");

Console.WriteLine(cookiePair.ToString()); // Output: sessionid=12345abc
Console.WriteLine(customHeader.Name);     // Output: X-Custom-Header
                    

Remarks

The KeyValuePairHeaderValue class is used to represent common HTTP header patterns that consist of a name-value pair, such as cookies.

It provides a convenient way to manage and parse these types of header values.