HttpCacheDirectiveHeaderValueCollection 類別

定義

表示與 HTTP 要求或回應相關聯的 HTTP 內容上快 取控制 HTTP 標頭的值。

public ref class HttpCacheDirectiveHeaderValueCollection sealed : IIterable<HttpNameValueHeaderValue ^>, IVector<HttpNameValueHeaderValue ^>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HttpCacheDirectiveHeaderValueCollection final : IIterable<HttpNameValueHeaderValue>, IVector<HttpNameValueHeaderValue>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HttpCacheDirectiveHeaderValueCollection final : IIterable<HttpNameValueHeaderValue>, IVector<HttpNameValueHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HttpCacheDirectiveHeaderValueCollection : IEnumerable<HttpNameValueHeaderValue>, IList<HttpNameValueHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class HttpCacheDirectiveHeaderValueCollection : IEnumerable<HttpNameValueHeaderValue>, IList<HttpNameValueHeaderValue>, IStringable
Public NotInheritable Class HttpCacheDirectiveHeaderValueCollection
Implements IEnumerable(Of HttpNameValueHeaderValue), IList(Of HttpNameValueHeaderValue), IStringable
繼承
Object Platform::Object IInspectable HttpCacheDirectiveHeaderValueCollection
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

下列範例程式碼示範使用 HttpCacheDirectiveHeaderValueCollection 類別的屬性和方法,在HttpRequestMessage物件上取得和設定Cache-Control HTTP 標頭的方法。

using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

        public void DemonstrateHeaderRequestCacheControl() {
            var request = new HttpRequestMessage();
            bool parsedOk = false;

            // Set the header with a string.
            parsedOk = request.Headers.CacheControl.TryParseAdd("no-store");

            // Set the header with a strong type.
            request.Headers.CacheControl.Add(new HttpNameValueHeaderValue("max-age", "10"));

            // Get the strong type out
            foreach (var value in request.Headers.CacheControl) {
                System.Diagnostics.Debug.WriteLine("One of the CacheControl values: {0}={1}", value.Name, value.Value);
            }

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

下列範例程式碼示範使用 HttpCacheDirectiveHeaderValueCollection 類別的屬性和方法,在HttpResponseMessage物件上取得和設定Cache-Control HTTP 標頭的方法。

using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

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

            // Set the header with a string
            response.Headers.CacheControl.TryParseAdd("public");

            // Set the header with a strong type
            response.Headers.CacheControl.Add(new HttpNameValueHeaderValue("max-age", "30"));

            // Get the strong type out
            foreach (var value in response.Headers.CacheControl) {
                System.Diagnostics.Debug.WriteLine("CacheControl {0}={1}", value.Name, value.Value);
            }

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

備註

HttpCacheDirectiveHeaderValueCollection 類別代表與 HTTP 要求或 HTTP 回應相關聯之 HTTP 內容上快 取控制 HTTP 標頭的值。

HttpRequestHeaderCollection上的CacheControl屬性會傳回 HttpCacheDirectiveHeaderValueCollection。 HttpResponseHeaderCollection上的CacheControl屬性會傳回 HttpCacheDirectiveHeaderValueCollection。

集合成員清單

針對 JavaScript,HttpCacheDirectiveHeaderValueCollection 具有成員清單中顯示的成員。 此外,HttpCacheDirectiveHeaderValueCollection 支援 Array.prototype 的成員,並使用索引來存取專案。

列舉 C# 或 Microsoft Visual Basic 中的集合

您可以在 C# 或 Microsoft Visual Basic 中逐一查看 HttpCacheDirectiveHeaderValueCollection 物件。 在許多情況下,例如使用 foreach 語法,編譯器會為您執行此轉換,而且您不需要明確地轉換成 IEnumerable<HttpNameValueHeaderValue> 。 如果您需要明確轉換,例如,如果您想要呼叫GetEnumerator,請使用HttpNameValueHeaderValue條件約束將集合物件轉換成IEnumerable < T >

屬性

MaxAge

取得或設定Cache-Control HTTP 標頭中max-age指示詞的值。

MaxStale

取得或設定Cache-Control HTTP 標頭中max-stale 指示詞的值。

MinFresh

取得或設定Cache-Control HTTP 標頭中min-fresh指示詞的值。

SharedMaxAge

取得或設定Cache-Control HTTP 標頭中s-maxage指示詞的值。

Size

取得集合中的 HttpNameValueHeaderValue 物件數目。

方法

Append(HttpNameValueHeaderValue)

將新的 HttpNameValueHeaderValue 專案加入集合結尾。

Clear()

從集合中移除所有物件。

First()

擷取反覆運算器至集合中的第一個 HttpNameValueHeaderValue 專案。

GetAt(UInt32)

傳回集合中指定索引處的 HttpNameValueHeaderValue

GetMany(UInt32, HttpNameValueHeaderValue[])

擷取從集合中指定索引處開始的 HttpNameValueHeaderValue 專案。

GetView()

傳回 HttpCacheDirectiveHeaderValueCollection的不可變檢視。

IndexOf(HttpNameValueHeaderValue, UInt32)

擷取集合中 HttpNameValueHeaderValue 的索引。

InsertAt(UInt32, HttpNameValueHeaderValue)

HttpNameValueHeaderValue 插入集合中指定的索引處。

ParseAdd(String)

剖析並新增專案至 HttpCacheDirectiveHeaderValueCollection

RemoveAt(UInt32)

HttpCacheDirectiveHeaderValueCollection移除位於指定索引處的專案。

RemoveAtEnd()

從集合中移除最後一個 HttpNameValueHeaderValue 專案。

ReplaceAll(HttpNameValueHeaderValue[])

以指定的HttpNameValueHeaderValue 專案取代集合中的所有 HttpNameValueHeaderValue專案。

SetAt(UInt32, HttpNameValueHeaderValue)

在集合中指定的索引處設定 HttpNameValueHeaderValue

ToString()

會傳回代表目前 HttpCacheDirectiveHeaderValueCollection 物件的字串。

TryParseAdd(String)

嘗試剖析並新增指定的專案至 HttpCacheDirectiveHeaderValueCollection

適用於

另請參閱