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());
}

適用於

另請參閱