HttpParameterValue Class

Represents a parameter value for an HTTP header. This class is typically used to represent the value of a single parameter within a header, such as the q value in a Accept header.

Namespace

System.Net.Http.Headers

Assembly

System.Net.Http.Formatting.dll

Syntax

public class HttpParameterValue

Description

The HttpParameterValue class provides a way to construct and manipulate parameter values that are commonly found in HTTP headers. It ensures that these values are correctly formatted and encoded according to HTTP specifications. This class is immutable, meaning once an instance is created, its value cannot be changed.

Constructors

Properties

Name Type Description
Value string Gets the string representation of the parameter value.

Methods

Example

The following example demonstrates how to create and use HttpParameterValue to represent a quality factor (q) in an Accept header.

using System.Net.Http.Headers;

// Creating an HttpParameterValue for a quality factor of 0.7
HttpParameterValue qualityValue = new HttpParameterValue("0.7");

// Accessing the string value
string valueAsString = qualityValue.Value; // "0.7"

// You would typically use this with other header values, e.g., MediaWithQualityHeaderValue
// This is a simplified representation.
Console.WriteLine($"Parameter value: {qualityValue.ToString()}");

Remarks

When constructing HttpParameterValue, the provided string will be used directly. It is the responsibility of the developer to ensure that the string value is valid for the intended HTTP header parameter.

See Also