System.Net.Http.Headers
Assembly:
System.Net.Http.Primitives
Represents a header value that consists of a name and a value.
Initializes a new instance of the KeyValuePairHeaderValue class.
public KeyValuePairHeaderValue(string name, string value)
Initializes a new instance of the KeyValuePairHeaderValue class.
public KeyValuePairHeaderValue(string name)
Gets or sets the name of the header value.
public string Name { get; set; }
Gets or sets the value of the header value.
public string Value { get; set; }
Returns a string representation of the KeyValuePairHeaderValue object.
public override string ToString()
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Serves as the default hash function.
public override int GetHashCode()
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
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.