(0) exportieren Drucken
Alle erweitern

OidEnumerator.Reset-Methode

Aktualisiert: November 2007

Legt einen Enumerator auf seine Anfangsposition fest.

Namespace:  System.Security.Cryptography
Assembly:  System (in System.dll)

public void Reset()
public final void Reset()
public final function Reset()

Implementiert

IEnumerator.Reset()

AusnahmeBedingung
InvalidOperationException

Die Auflistung wurde nach dem Erstellen des Enumerators geändert.

Die Anfangsposition eines Enumerators befindet sich vor dem ersten Element im OidCollection-Objekt. Ein Enumerator bleibt so lange gültig, bis die Auflistung geändert wird. Wenn an der Auflistung Änderungen vorgenommen werden, z. B. durch Hinzufügen, Ändern oder Entfernen von Elementen, wird der Enumerator ungültig, und der nächste Aufruf der Reset-Methode löst eine InvalidOperationException aus.

Im folgenden Codebeispiel wird die Verwendung der OidEnumerator-Klasse veranschaulicht.

using System;
using System.Security.Cryptography;
public class OidSample
{
	public static void Main()
	{
		// Assign values to strings.
		string Value1 = "1.2.840.113549.1.1.1";
		string Name1 = "3DES";
		string Value2 = "1.3.6.1.4.1.311.20.2";
		string InvalidName = "This name is not a valid name";
		string InvalidValue = "1.1.1.1.1.1.1.1";

		// Create new Oid objects using the specified values.
		// Note that the corresponding Value or Friendly Name property is automatically added to the object.
		Oid o1 = new Oid(Value1);
		Oid o2 = new Oid(Name1);

		// Create a new Oid object using the specified Value and Friendly Name properties.
		// Note that the two are not compared to determine if the Value is associated 
		//  with the Friendly Name.
		Oid o3 = new Oid(Value2, InvalidName);

		//Create a new Oid object using the specified Value. Note that if the value
		//  is invalid or not known, no value is assigned to the Friendly Name property.
		Oid o4 = new Oid(InvalidValue);

		//Write out the property information of the Oid objects.
		Console.WriteLine("Oid1: Automatically assigned Friendly Name: {0}, {1}", o1.FriendlyName, o1.Value);
		Console.WriteLine("Oid2: Automatically assigned Value: {0}, {1}", o2.FriendlyName, o2.Value);
		Console.WriteLine("Oid3: Name and Value not compared: {0}, {1}", o3.FriendlyName, o3.Value);
		Console.WriteLine("Oid4: Invalid Value used: {0}, {1} {2}", o4.FriendlyName, o4.Value, Environment.NewLine);

		//Create an Oid collection and add several Oid objects.
		OidCollection oc = new OidCollection();
		oc.Add(o1);
		oc.Add(o2);
		oc.Add(o3);
		Console.WriteLine("Number of Oids in the collection: {0}", oc.Count);
		Console.WriteLine("Is synchronized: {0} {1}", oc.IsSynchronized, Environment.NewLine);

		//Create an enumerator for moving through the collection.
		OidEnumerator oe = oc.GetEnumerator();
		//You must execute a MoveNext() to get to the first item in the collection.
		oe.MoveNext();
		// Write out Oids in the collection.
		Console.WriteLine("First Oid in collection: {0},{1}", oe.Current.FriendlyName,oe.Current.Value);
		oe.MoveNext();
		Console.WriteLine("Second Oid in collection: {0},{1}", oe.Current.FriendlyName, oe.Current.Value);
		//Return index in the collection to the beginning.
		oe.Reset();
	}
}


import System.*;
import System.Security.Cryptography.*;

public class OidSample
{
    public static void main(String args[])
    {
        // Assign values to strings.
        String value1 = "1.2.840.113549.1.1.1";
        String name1 = "3DES";
        String value2 = "1.3.6.1.4.1.311.20.2";
        String invalidName = "This name is not a valid name";
        String invalidValue = "1.1.1.1.1.1.1.1";
        // Create new Oid objects using the specified values.
        // Note that the corresponding Value or Friendly Name property 
        // is automatically added to the object.
        Oid o1 = new Oid(value1);
        Oid o2 = new Oid(name1);
        // Create a new Oid object using the specified Value and Friendly 
        // Name properties.
        // Note that the two are not compared to determine if the Value is 
        // associated with the Friendly Name.
        Oid o3 = new Oid(value2, invalidName);
        // Create a new Oid object using the specified Value. Note that if the
        // value is invalid or not known, no value is assigned to the Friendly 
        // Name property.
        Oid o4 = new Oid(invalidValue);
        //Write out the property information of the Oid objects.
        Console.WriteLine("Oid1: Automatically assigned Friendly Name: {0}, {1}",
            o1.get_FriendlyName(), o1.get_Value());
        Console.WriteLine("Oid2: Automatically assigned Value: {0}, {1}", 
            o2.get_FriendlyName(), o2.get_Value());
        Console.WriteLine("Oid3: Name and Value not compared: {0}, {1}", 
            o3.get_FriendlyName(), o3.get_Value());
        Console.WriteLine("Oid4: Invalid Value used: {0}, {1} {2}", 
            o4.get_FriendlyName(), o4.get_Value(), Environment.get_NewLine());
        //Create an Oid collection and add several Oid objects.
        OidCollection oc = new OidCollection();
        oc.Add(o1);
        oc.Add(o2);
        oc.Add(o3);
        Console.WriteLine("Number of Oids in the collection: {0}", 
            System.Convert.ToString(oc.get_Count()));
        Console.WriteLine("Is synchronized: {0} {1}", 
            System.Convert.ToString(oc.get_IsSynchronized()), 
            Environment.get_NewLine());
        //Create an enumerator for moving through the collection.
        OidEnumerator oe = oc.GetEnumerator();
        //You must execute a MoveNext() to get to the first item in the
        //collection.
        oe.MoveNext();
        // Write out Oids in the collection.
        Console.WriteLine("First Oid in collection: {0},{1}", 
            oe.get_Current().get_FriendlyName(), 
            oe.get_Current().get_Value());
        oe.MoveNext();
        Console.WriteLine("Second Oid in collection: {0},{1}",
            oe.get_Current().get_FriendlyName(), oe.get_Current().get_Value());
        //Return index in the collection to the beginning.
        oe.Reset();
    } //main
} //OidSample


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework und .NET Compact Framework unterstützen nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.

.NET Framework

Unterstützt in: 3.5, 3.0, 2.0

Community-Beiträge

HINZUFÜGEN
Anzeigen:
© 2014 Microsoft