CookieCollection.Item[] 屬性

定義

Cookie 中取得特定的 CookieCollection

多載

Item[Int32]

Cookie 中特定的索引處取得 CookieCollection

Item[String]

Cookie 中以特定的名稱取得 CookieCollection

Item[Int32]

Cookie 中特定的索引處取得 CookieCollection

public:
 property System::Net::Cookie ^ default[int] { System::Net::Cookie ^ get(int index); };
public System.Net.Cookie this[int index] { get; }
member this.Item(int) : System.Net.Cookie
Default Public ReadOnly Property Item(index As Integer) As Cookie

參數

index
Int32

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

屬性值

Cookie

Cookie 中特定索引處的 CookieCollection

例外狀況

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

範例

// 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 ] );
   Console::WriteLine( "" );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( "Exception raised.\nError : {0}", e->Message );
}
  // 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);
  }
 '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
    Dim j As Integer
    For j = 0 To cookies.Count - 1
        Console.WriteLine("{0}", cookies(j).ToString())
    Next j
    Console.WriteLine("")
Catch e As Exception
    Console.WriteLine(("Exception raised." + ControlChars.Cr + "Error : " + e.Message))
End Try

備註

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

另請參閱

適用於

Item[String]

Cookie 中以特定的名稱取得 CookieCollection

public:
 property System::Net::Cookie ^ default[System::String ^] { System::Net::Cookie ^ get(System::String ^ name); };
public System.Net.Cookie this[string name] { get; }
public System.Net.Cookie? this[string name] { get; }
member this.Item(string) : System.Net.Cookie
Default Public ReadOnly Property Item(name As String) As Cookie

參數

name
String

要尋找的 Cookie 名稱。

屬性值

Cookie

Cookie 中具有特定名稱的 CookieCollection

例外狀況

namenull

範例

// 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" ] );
   Console::WriteLine( "{0}", cookies[ "DateOfBirth" ] );
   Console::WriteLine( "{0}", cookies[ "PlaceOfBirth" ] );
   Console::WriteLine( "" );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( "Exception raised.\nError : {0}", e->Message );
}
// 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);
}
' 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

備註

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

另請參閱

適用於