HttpCookieCollection.Get Method (Int32)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Use BaseTrue

Returns the HttpCookie item with the specified index from the cookie collection.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)

public HttpCookie Get(
	int index


Type: System.Int32

The index of the cookie to return from the collection.

Return Value

Type: System.Web.HttpCookie

The HttpCookie specified by index.

The following example returns each cookie from the cookie collection, checks whether it is named "LastVisit", and, if "LastVisit" is found, updates its value to the current date and time.

int loop1;
 HttpCookie MyCookie;
 HttpCookieCollection MyCookieCollection = Response.Cookies;

 for(loop1 = 0; loop1 < MyCookieCollection.Count; loop1++)
    MyCookie = MyCookieCollection.Get(loop1);
    if(MyCookie.Value == "LastVisit")
       MyCookie.Value = DateTime.Now.ToString();

.NET Framework
Available since 1.1
Return to top