HttpRangesHeaderValue Class

Represents a Range header value.

namespace System.Net.Http.Headers { public sealed class HttpRangesHeaderValue : ICloneable { // Fields and Properties public HttpRangesHeaderValue(long offset, long? length = null); public HttpRangesHeaderValue(long offset, long size, long end); public static HttpRangesHeaderValue Parse(string input); public static bool TryParse(string input, out HttpRangesHeaderValue parsedValue); // Methods public object Clone(); public override string ToString(); } }

Summary

The HttpRangesHeaderValue class in the System.Net.Http.Headers namespace is used to represent the value of an HTTP Range header. This header is typically used by clients to request only a part of a resource, for example, to download large files in chunks or to resume an interrupted download.

Constructors

HttpRangesHeaderValue(long offset, long? length = null)

Initializes a new instance of the HttpRangesHeaderValue class with the specified byte range offset and optional length.

Parameters

Parameter Type Description
offset long The starting byte offset of the range.
length long? The optional length of the range in bytes. If null, it signifies an open-ended range from the offset to the end of the resource.

HttpRangesHeaderValue(long offset, long size, long end)

Initializes a new instance of the HttpRangesHeaderValue class with the specified byte range offset, size, and end position.

Parameters

Parameter Type Description
offset long The starting byte offset of the range.
size long The size of the range in bytes.
end long The ending byte position of the range.

Methods

Parse(string input)

Parses a string into an HttpRangesHeaderValue instance.

Parameters

Parameter Type Description
input string The string to parse.

Returns

An HttpRangesHeaderValue instance created from the input string.

Note: This method will throw a FormatException if the input string is not valid.

TryParse(string input, out HttpRangesHeaderValue parsedValue)

Attempts to parse a string into an HttpRangesHeaderValue instance.

Parameters

Parameter Type Description
input string The string to parse.
parsedValue out HttpRangesHeaderValue When this method returns, contains the parsed HttpRangesHeaderValue if the parsing succeeded, or null if the parsing failed.

Returns

true if the input string was parsed successfully; otherwise, false.

Tip: Use this method to avoid exceptions when dealing with potentially invalid input.

Clone()

Creates a deep copy of the current instance.

Returns

A deep copy of the current HttpRangesHeaderValue instance.

ToString()

Returns a string representation of the HttpRangesHeaderValue object.

Returns

A string representing the Range header value (e.g., "bytes=0-999").

See Also