次の方法で共有


CookieCollection.Item プロパティ

CookieCollection から特定の Cookie を取得します。

[C#] C# では、このプロパティは CookieCollection クラスのインデクサになります。

オーバーロードの一覧

CookieCollection から特定のインデックスを持つ Cookie を取得します。

[Visual Basic] Overloads Public Default ReadOnly Property Item(Integer) As Cookie

[C#] public Cookie this[int] {get;}

[C++] public: __property Cookie* get_Item(int);

[JScript] CookieCollection.Item (int)

CookieCollection から特定の名前の Cookie を取得します。

[Visual Basic] Overloads Public Default ReadOnly Property Item(String) As Cookie

[C#] public Cookie this[string] {get;}

[C++] public: __property Cookie* get_Item(String*);

[JScript] CookieCollection.Item (String)

使用例

[Visual Basic, C#, C++] メモ   ここでは、Item プロパティ (CookieCollection インデクサ) のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
' Get the cookies in the 'CookieCollection' object using the 'Item' property.
         
        
        Try
If cookies.Count = 0 Then
    Console.WriteLine("No cookies to display")
    Return
End If
Console.WriteLine("{0}", cookies("UserName").ToString())
Console.WriteLine("{0}", cookies("DateOfBirth").ToString())
Console.WriteLine("{0}", cookies("PlaceOfBirth").ToString())
Console.WriteLine("")
        Catch e As Exception
Console.WriteLine(("Exception raised." + ControlChars.Cr + "Error : " + e.Message))
        End Try

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

[C++] 
// Get the cookies in the 'CookieCollection' object using the 'Item' property.
try {
   if(cookies->Count == 0) {
      Console::WriteLine(S"No cookies to display");
      return;
   }
   Console::WriteLine(S"{0}", cookies->Item[S"UserName"]);
   Console::WriteLine(S"{0}", cookies->Item[S"DateOfBirth"]);
   Console::WriteLine(S"{0}", cookies->Item[S"PlaceOfBirth"]);
   Console::WriteLine(S"");
}
catch(Exception* e) {
   Console::WriteLine(S"Exception raised.\nError : {0}", e->Message);
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

CookieCollection クラス | CookieCollection メンバ | System.Net 名前空間