This documentation is archived and is not being maintained.

CookieCollection.Item Property

Gets a specific Cookie from a CookieCollection.

[C#] In C#, this property is the indexer for the CookieCollection class.

Overload List

Gets the Cookie with a specific index from a CookieCollection.

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

Gets the Cookie with a specific name from a CookieCollection.

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

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the Item property (CookieCollection indexer). For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' 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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

CookieCollection Class | CookieCollection Members | System.Net Namespace

Show: