HttpResponseHeaderCollection.Age 属性

定义

获取或设置 TimeSpan 对象,该对象代表 HTTP 响应上的 Age HTTP 标头的值。

public:
 property IReference<TimeSpan> ^ Age { IReference<TimeSpan> ^ get(); void set(IReference<TimeSpan> ^ value); };
IReference<TimeSpan> Age();

void Age(IReference<TimeSpan> value);
public System.Nullable<System.TimeSpan> Age { get; set; }
var iReference = httpResponseHeaderCollection.age;
httpResponseHeaderCollection.age = iReference;
Public Property Age As Nullable(Of TimeSpan)

属性值

对象,表示 HTTP 响应上的 Age HTTP 标头的值。 null 值表示标头不存在。

注解

Age 属性表示 HTTP 响应上的 Age 标头的值。 Age 标头是缓存中实体的期限。

使用 .NET 编程时,此结构是隐藏的,开发人员应使用 System.TimeSpan 结构。 该值可以为 null,因为它被键入为 TimeSpan? (可为 null 的 TimeSpan) 。

在 JavaScript 中,此结构作为值而不是对象进行访问。 例如,使用 var a = 10000,而不是 var a = { duration: 10000 }

注意

在 JavaScript 中,此结构被视为毫秒间隔数,而不是 100 纳秒间隔数。 因此,在语言之间移植时 ,Windows.Foundation.TimeSpan 值可能会失去精度。

有关更多详细信息,请参阅 Windows.Foundation.TimeSpan 接口。

下面的示例代码演示了一个方法,该方法使用 HttpResponseHeaderCollection 对象的 Age 属性在 HttpResponseMessage 对象上设置 Age 标头。

public void DemonstrateHeaderResponseAge() {
    var response = new HttpResponseMessage();

    // Set the header with a strong type.
    DateTimeOffset value = DateTimeOffset.UtcNow;
    response.Headers.Age = new TimeSpan(1, 35, 55); // 1 hour, 35 minutes, 55 seconds.

    // Get the strong type out
    System.Diagnostics.Debug.WriteLine("Age value in minutes: {0}", response.Headers.Age.Value.TotalMinutes);

    // The ToString() is useful for diagnostics, too.
    System.Diagnostics.Debug.WriteLine("The Age ToString() results: {0}", response.Headers.Age.ToString());
}

适用于

另请参阅