CookieCollection.Item[] 屬性

定義

Cookie 中取得特定的 CookieCollection

多載

Item[Int32]

Cookie 中特定的索引處取得 CookieCollection

Item[String]

Cookie 中以特定的名稱取得 CookieCollection

Item[Int32]

來源:
CookieCollection.cs
來源:
CookieCollection.cs
來源:
CookieCollection.cs

Cookie 中特定的索引處取得 CookieCollection

C#
public System.Net.Cookie this[int index] { get; }

參數

index
Int32

要尋找之 Cookie 的以零起始的索引。

屬性值

Cookie 中特定索引處的 CookieCollection

例外狀況

index 小於 0,或 index 大於或等於 Count

範例

C#
  // Get the cookies in the 'CookieCollection' object using the 'Item' property.
  // The 'Item' property in C# is implemented through Indexers.
// The class that implements indexers is usually a collection of other objects.
// This class provides access to those objects with the '<class-instance>[i]' syntax.
  try {
      if(cookies.Count == 0) {
          Console.WriteLine("No cookies to display");
          return;
      }
      for(int j = 0; j < cookies.Count; j++)
          Console.WriteLine("{0}", cookies[j].ToString());
      Console.WriteLine("");
  }
  catch(Exception e) {
      Console.WriteLine("Exception raised.\nError : " + e.Message);
  }

備註

您可以使用這個 來逐一查看 的內容 CookieCollection

另請參閱

適用於

.NET 10 和其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Item[String]

來源:
CookieCollection.cs
來源:
CookieCollection.cs
來源:
CookieCollection.cs

Cookie 中以特定的名稱取得 CookieCollection

C#
public System.Net.Cookie this[string name] { get; }
C#
public System.Net.Cookie? this[string name] { get; }

參數

name
String

要尋找的 Cookie 名稱。

屬性值

Cookie 中具有特定名稱的 CookieCollection

例外狀況

namenull

範例

C#
// Get the cookies in the 'CookieCollection' object using the 'Item' property.
// The 'Item' property in C# is implemented through Indexers.
// The class that implements indexers is usually a collection of other objects.
// This class provides access to those objects with the '<class-instance>[i]' syntax.
try {
    if(cookies.Count == 0) {
        Console.WriteLine("No cookies to display");
        return;
    }
    Console.WriteLine("{0}", cookies["UserName"].ToString());
    Console.WriteLine("{0}", cookies["DateOfBirth"].ToString());
    Console.WriteLine("{0}", cookies["PlaceOfBirth"].ToString());
    Console.WriteLine("");
}
catch(Exception e) {
    Console.WriteLine("Exception raised.\nError : " + e.Message);
}

備註

您可以使用這個 來逐一查看 的內容 CookieCollection

另請參閱

適用於

.NET 10 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0