AmbiguousMatchException Constructors

Definitie

Initialiseert een nieuw exemplaar van de AmbiguousMatchException klasse.

Overloads

Name Description
AmbiguousMatchException()

Initialiseert een nieuw exemplaar van de AmbiguousMatchException klasse met een lege berichttekenreeks en de hoofdoorzaakuitzondering ingesteld op null.

AmbiguousMatchException(String)

Initialiseert een nieuw exemplaar van de AmbiguousMatchException klasse met de bijbehorende berichttekenreeks die is ingesteld op het opgegeven bericht en de uitzondering voor de hoofdoorzaak ingesteld op null.

AmbiguousMatchException(String, Exception)

Initialiseert een nieuw exemplaar van de AmbiguousMatchException klasse met een opgegeven foutbericht en een verwijzing naar de binnenste uitzondering die de oorzaak van deze uitzondering is.

AmbiguousMatchException()

Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs

Initialiseert een nieuw exemplaar van de AmbiguousMatchException klasse met een lege berichttekenreeks en de hoofdoorzaakuitzondering ingesteld op null.

public:
 AmbiguousMatchException();
public AmbiguousMatchException();
Public Sub New ()

Opmerkingen

AmbiguousMatchException neemt over van Exception. Met deze constructor worden de eigenschappen van het Exception object ingesteld, zoals wordt weergegeven in de volgende tabel.

Vastgoed Waarde
InnerException null
Message De lege tekenreeks ("").

Zie ook

Van toepassing op

AmbiguousMatchException(String)

Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs

Initialiseert een nieuw exemplaar van de AmbiguousMatchException klasse met de bijbehorende berichttekenreeks die is ingesteld op het opgegeven bericht en de uitzondering voor de hoofdoorzaak ingesteld op null.

public:
 AmbiguousMatchException(System::String ^ message);
public AmbiguousMatchException(string message);
public AmbiguousMatchException(string? message);
new System.Reflection.AmbiguousMatchException : string -> System.Reflection.AmbiguousMatchException
Public Sub New (message As String)

Parameters

message
String

Een tekenreeks die aangeeft waarom deze uitzondering is gegenereerd.

Opmerkingen

AmbiguousMatchException neemt over van Exception. Met deze constructor worden de eigenschappen van het Exception object ingesteld, zoals wordt weergegeven in de volgende tabel.

Vastgoed Waarde
InnerException null
Message De message tekenreeks.

Van toepassing op

AmbiguousMatchException(String, Exception)

Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs
Bron:
AmbiguousMatchException.cs

Initialiseert een nieuw exemplaar van de AmbiguousMatchException klasse met een opgegeven foutbericht en een verwijzing naar de binnenste uitzondering die de oorzaak van deze uitzondering is.

public:
 AmbiguousMatchException(System::String ^ message, Exception ^ inner);
public AmbiguousMatchException(string message, Exception inner);
public AmbiguousMatchException(string? message, Exception? inner);
new System.Reflection.AmbiguousMatchException : string * Exception -> System.Reflection.AmbiguousMatchException
Public Sub New (message As String, inner As Exception)

Parameters

message
String

In het foutbericht wordt de reden voor de uitzondering uitgelegd.

inner
Exception

De uitzondering die de oorzaak is van de huidige uitzondering. Als de inner parameter niet nullis, wordt de huidige uitzondering gegenereerd in een catch blok dat de binnenste uitzondering afhandelt.

Voorbeelden

In het volgende voorbeeld ziet u twee methoden, elk met de naam Mymethod. De ene methode neemt een geheel getal op en de andere gebruikt een tekenreeks. Als een geheel getal wordt doorgegeven aan Mymethod, wordt de eerste methode gebruikt. Als een tekenreeks wordt doorgegeven, wordt de tweede methode gebruikt. Als het niet kan worden bepaald welke Mymethod te gebruiken, AmbiguousMatchException wordt gegenereerd.

using System;
using System.Reflection;

namespace Ambiguity
{
    class Myambiguous
    {
        //The first overload is typed to an int
        public static void Mymethod(int number)
        {
           Console.WriteLine("I am from 'int' method");
        }

        //The second overload is typed to a string
        public static void Mymethod(string alpha)
        {
            Console.WriteLine("I am from 'string' method.");
        }

        public static void Main()
        {
            try
            {
                //The following does not cause as exception
                Mymethod(2);    // goes to Mymethod(int)
                Mymethod("3");  // goes to Mymethod(string)

                Type Mytype = Type.GetType("Ambiguity.Myambiguous");

                MethodInfo Mymethodinfo32 = Mytype.GetMethod("Mymethod", new Type[]{typeof(int)});
                MethodInfo Mymethodinfostr = Mytype.GetMethod("Mymethod", new Type[]{typeof(System.String)});

                //Invoke a method, utilizing a int integer
                Mymethodinfo32.Invoke(null, new Object[]{2});

                //Invoke the method utilizing a string
                Mymethodinfostr.Invoke(null, new Object[]{"1"});

                //The following line causes an ambiguious exception
                MethodInfo Mymethodinfo = Mytype.GetMethod("Mymethod");
            }   // end of try block
            catch (AmbiguousMatchException ex)
            {
                Console.WriteLine("\n{0}\n{1}", ex.GetType().FullName, ex.Message);
            }
            catch
            {
                Console.WriteLine("\nSome other exception.");
            }
            return;
        }
    }
}

//This code produces the following output:
//
// I am from 'int' method
// I am from 'string' method.
// I am from 'int' method
// I am from 'string' method.

// System.Reflection.AmbiguousMatchException
// Ambiguous match found.
Imports System.Reflection

Namespace Ambiguity
    Class Myambiguous

        'The first overload is typed to an Int32
        Overloads Public Shared Sub Mymethod(number As Int32)
            Console.WriteLine("I am from 'Int32' method")
        End Sub

        'The second overload is typed to a string
        Overloads Public Shared Sub Mymethod(alpha As String)
            Console.WriteLine("I am from 'string' method.")
        End Sub

        Public Shared Sub Main()
            Try
                'The following does not cause as exception
                Mymethod(2) ' goes to Mymethod Int32)
                Mymethod("3") ' goes to Mymethod(string)
                Dim Mytype As Type = Type.GetType("Ambiguity.Myambiguous")

                Dim Mymethodinfo32 As MethodInfo = Mytype.GetMethod("Mymethod", New Type() {GetType(Int32)})
                Dim Mymethodinfostr As MethodInfo = Mytype.GetMethod("Mymethod", New Type() {GetType(System.String)})

                'Invoke a method, utilizing a Int32 integer
                Mymethodinfo32.Invoke(Nothing, New Object() {2})

                'Invoke the method utilizing a string
                Mymethodinfostr.Invoke(Nothing, New Object() {"1"})

                'The following line causes an ambiguious exception
                Dim Mymethodinfo As MethodInfo = Mytype.GetMethod("Mymethod")
                ' end of try block
            Catch ex As AmbiguousMatchException
                Console.WriteLine(Environment.NewLine + "{0}" + Environment.NewLine + "{1}", ex.GetType().FullName, ex.Message)
            Catch
                Console.WriteLine(Environment.NewLine + "Some other exception.")
            End Try
            Return
        End Sub
    End Class
End Namespace
' This code produces the following output:
'
' I am from 'Int32' method
' I am from 'string' method.
' I am from 'Int32' method
' I am from 'string' method.
'
' System.Reflection.AmbiguousMatchException
' Ambiguous match found.

Opmerkingen

Een uitzondering die wordt gegenereerd als direct resultaat van een vorige uitzondering, moet een verwijzing naar de vorige uitzondering in de InnerException eigenschap bevatten. De InnerException eigenschap retourneert dezelfde waarde die wordt doorgegeven aan de constructor of null als de InnerException eigenschap de binnenste uitzonderingswaarde niet aan de constructor levert.

In de volgende tabel ziet u de oorspronkelijke eigenschapswaarden voor een exemplaar van AmbiguousMatchException.

Vastgoed Waarde
InnerException De interne uitzonderingsreferentie.
Message De tekenreeks van het foutbericht.

Zie ook

Van toepassing op