Nyelv

AmbiguousMatchException Konstruktorok

Definíció

Inicializálja a AmbiguousMatchException osztály új példányát.

Túlterhelések

Name Description
AmbiguousMatchException()

Inicializálja az AmbiguousMatchException osztály új példányát egy üres üzenetsztringgel, és a kiváltó ok kivétele a következőre nullvan állítva: .

AmbiguousMatchException(String)

Inicializálja az osztály új példányát, AmbiguousMatchException amelynek üzenetsztringje az adott üzenetre van állítva, a kiváltó ok kivétele pedig a következőre nullvan állítva: .

AmbiguousMatchException(String, Exception)

Inicializálja az AmbiguousMatchException osztály új példányát egy megadott hibaüzenettel és a kivétel okaként szolgáló belső kivételre mutató hivatkozással.

AmbiguousMatchException()

Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs

Inicializálja az AmbiguousMatchException osztály új példányát egy üres üzenetsztringgel, és a kiváltó ok kivétele a következőre nullvan állítva: .

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

Megjegyzések

AmbiguousMatchException örököl Exception-től. Ez a konstruktor az objektum tulajdonságait állítja be az Exception alábbi táblázatban látható módon.

Ingatlan Érték
InnerException null
Message Az üres sztring ("").

Lásd még

A következőre érvényes:

AmbiguousMatchException(String)

Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs

Inicializálja az osztály új példányát, AmbiguousMatchException amelynek üzenetsztringje az adott üzenetre van állítva, a kiváltó ok kivétele pedig a következőre nullvan állítva: .

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)

Paraméterek

message
String

A kivétel okát jelző sztring.

Megjegyzések

AmbiguousMatchException örököl Exception-től. Ez a konstruktor az objektum tulajdonságait állítja be az Exception alábbi táblázatban látható módon.

Ingatlan Érték
InnerException null
Message A message sztring.

A következőre érvényes:

AmbiguousMatchException(String, Exception)

Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs
Forrás:
AmbiguousMatchException.cs

Inicializálja az AmbiguousMatchException osztály új példányát egy megadott hibaüzenettel és a kivétel okaként szolgáló belső kivételre mutató hivatkozással.

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)

Paraméterek

message
String

A kivétel okát magyarázó hibaüzenet.

inner
Exception

Az aktuális kivétel okaként megadott kivétel. Ha a inner paraméter nem null, a rendszer az aktuális kivételt a catch belső kivételt kezelő blokkban emeli ki.

Példák

Az alábbi példa két metódust mutat be, mindegyik neve .Mymethod Az egyik metódus egy egész számot, a másik pedig egy sztringet vesz fel. Ha egy egész számot ad át Mymethod, a rendszer az első metódust használja. Ha egy sztringet ad át, a rendszer a második metódust használja. Ha nem határozható meg, hogy melyiket Mymethod kell használni, AmbiguousMatchException a rendszer eldobja.

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.

Megjegyzések

Az előző kivétel közvetlen eredményeként keletkező kivételnek tartalmaznia kell a tulajdonság előző kivételére InnerException mutató hivatkozást. A InnerException tulajdonság ugyanazt az értéket adja vissza, amelyet a konstruktornak ad át, vagy null ha a InnerException tulajdonság nem adja meg a belső kivétel értékét a konstruktornak.

Az alábbi táblázat a példány kezdeti tulajdonságértékét AmbiguousMatchExceptionmutatja be.

Ingatlan Érték
InnerException A belső kivételre mutató hivatkozás.
Message A hibaüzenet sztringje.

Lásd még

A következőre érvényes: