CookieCollection.Item[] Property

Definition

Gets a specific Cookie from a CookieCollection.

Overloads

Item[Int32]

Gets the Cookie with a specific index from a CookieCollection.

Item[String]

Gets the Cookie with a specific name from a CookieCollection.

Item[Int32]

Source:
CookieCollection.cs
Source:
CookieCollection.cs
Source:
CookieCollection.cs

Gets the Cookie with a specific index from a CookieCollection.

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

Parameters

index
Int32

The zero-based index of the Cookie to be found.

Property Value

A Cookie with a specific index from a CookieCollection.

Exceptions

index is less than 0 or index is greater than or equal to Count.

Examples

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

Remarks

You can use this to iterate over the contents of a CookieCollection.

See also

Applies to

.NET 10 and other versions
Product Versions
.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]

Source:
CookieCollection.cs
Source:
CookieCollection.cs
Source:
CookieCollection.cs

Gets the Cookie with a specific name from a CookieCollection.

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

Parameters

name
String

The name of the Cookie to be found.

Property Value

The Cookie with a specific name from a CookieCollection.

Exceptions

name is null.

Examples

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

Remarks

You can use this to iterate over the contents of a CookieCollection.

See also

Applies to

.NET 10 and other versions
Product Versions
.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