Represents a generic HTTP header value that can be parsed from a string.
Initializes a new instance of the GenericHeaderValue class with the specified string value.
Gets the string value of the generic header.
Determines whether the specified object is equal to the current object.
Serves as the default hash function.
Returns a string that represents the current object.
The GenericHeaderValue class is a simple way to represent HTTP header values that do not have a more specific type defined in the .NET framework. It allows you to store and retrieve header values as plain strings.
This class is useful when dealing with custom headers or headers that have a format not directly supported by built-in types.
using System;
using System.Net.Http.Headers;
public class Example
{
public static void Main(string[] args)
{
// Create a GenericHeaderValue for a custom header
GenericHeaderValue customHeader = new GenericHeaderValue("MyCustomValue");
Console.WriteLine($"Header Value: {customHeader.Value}");
Console.WriteLine($"Header String: {customHeader.ToString()}");
// Example with a standard but less common header format
GenericHeaderValue acceptRangesHeader = new GenericHeaderValue("bytes");
Console.WriteLine($"Accept-Ranges: {acceptRangesHeader.Value}");
}
}