ArrayTypeMismatchException Konstruktoren

Definition

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse.

Überlädt

ArrayTypeMismatchException()

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse.

ArrayTypeMismatchException(String)

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse mit einer angegebenen Fehlermeldung.

ArrayTypeMismatchException(SerializationInfo, StreamingContext)
Veraltet.

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse mit serialisierten Daten.

ArrayTypeMismatchException(String, Exception)

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse mit einer angegebenen Fehlermeldung und einem Verweis auf die innere Ausnahme, die diese Ausnahme ausgelöst hat.

ArrayTypeMismatchException()

Source:
ArrayTypeMismatchException.cs
Source:
ArrayTypeMismatchException.cs
Source:
ArrayTypeMismatchException.cs

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse.

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

Beispiele

Im folgenden Beispiel wird der ArrayTypeMismatchException()-Konstruktor der ArrayTypeMismatchException -Klasse veranschaulicht. Es enthält eine Funktion, die zwei Arrays als Argumente akzeptiert und überprüft, ob die beiden Arrays vom gleichen Typ sind. Wenn die Arrays unterschiedlicher Typen sind, wird ein neues ArrayTypeMismatchException ausgelöst und dann in der aufrufenden Methode abgefangen.

using namespace System;
public ref class ArrayTypeMisMatchConst
{
public:
   void CopyArray( Array^ myArray, Array^ myArray1 )
   {
      String^ typeArray1 = myArray->GetType()->ToString();
      String^ typeArray2 = myArray1->GetType()->ToString();
      
      // Check whether the two arrays are of same type or not.
      if ( typeArray1 == typeArray2 )
      {
         
         // Copy the values from one array to another.
         myArray->SetValue( String::Concat(  "Name: ", myArray1->GetValue( 0 )->ToString() ), 0 );
         myArray->SetValue( String::Concat(  "Name: ", myArray1->GetValue( 1 )->ToString() ), 1 );
      }
      else
      {
         
         // Throw an exception of type 'ArrayTypeMismatchException'.
         throw gcnew ArrayTypeMismatchException;
      }
   }

};

int main()
{
   try
   {
      array<String^>^myStringArray = gcnew array<String^>(2);
      myStringArray->SetValue( "Jones", 0 );
      myStringArray->SetValue( "John", 1 );
      array<Int32>^myIntArray = gcnew array<Int32>(2);
      ArrayTypeMisMatchConst^ myArrayType = gcnew ArrayTypeMisMatchConst;
      myArrayType->CopyArray( myStringArray, myIntArray );
   }
   catch ( ArrayTypeMismatchException^ e ) 
   {
      Console::WriteLine( "The Exception is : {0}", e );
   }

}
using System;

public class ArrayTypeMismatchConst
{
    public void CopyArray(Array myArray, Array myArray1)
    {
        string typeArray1 = myArray.GetType().ToString();
        string typeArray2 = myArray1.GetType().ToString();
        // Check whether the two arrays are of same type or not.
        if (typeArray1 == typeArray2)
        {
            // Copy the values from one array to another.
            myArray.SetValue("Name: " + myArray1.GetValue(0), 0);
            myArray.SetValue("Name: " + myArray1.GetValue(1), 1);
        }
        else
        {
            // Throw an exception of type 'ArrayTypeMismatchException'.
            throw new ArrayTypeMismatchException();
        }
    }
    static void Main()
    {
        try
        {
            string[] myStringArray = new string[2];
            myStringArray.SetValue("Jones", 0);
            myStringArray.SetValue("John", 1);

            int[] myIntArray = new int[2];
            ArrayTypeMismatchConst myArrayType = new();
            myArrayType.CopyArray(myStringArray, myIntArray);
        }
        catch (ArrayTypeMismatchException e)
        {
            Console.WriteLine("The Exception is :" + e);
        }
    }
}
open System

let copyArray (myArray: Array) (myArray1: Array) =
    let typeArray1 = myArray.GetType() |> string
    let typeArray2 = myArray1.GetType() |> string
    // Check whether the two arrays are of same type or not.
    if typeArray1 = typeArray2 then
        // Copy the values from one array to another.
        myArray.SetValue($"Name: {myArray1.GetValue 0}", 0)
        myArray.SetValue($"Name: {myArray1.GetValue 1}", 1)
    else
        // Throw an exception of type 'ArrayTypeMismatchException'.
        raise (ArrayTypeMismatchException())

try
    let myStringArray = [| "Jones"; "John" |]

    let myIntArray = Array.zeroCreate<int> 2

    copyArray myStringArray myIntArray

with :? ArrayTypeMismatchException as e -> 
    printfn $"The Exception is: {e}"
Public Class ArrayTypeMisMatchConst
   Public Sub CopyArray(myArray As Array, myArray1 As Array)
      
      Dim typeArray1 As String = myArray.GetType().ToString()
      Dim typeArray2 As String = myArray1.GetType().ToString()
      ' Check whether the two arrays are of same type or not.
      If typeArray1 = typeArray2 Then
         ' Copy the values from one array to another.
         myArray.SetValue("Name: " + myArray1.GetValue(0), 0)
         myArray.SetValue("Name: " + myArray1.GetValue(1), 1)
      Else
         ' Throw an exception of type 'ArrayTypeMismatchException'.
         Throw New ArrayTypeMismatchException()
      End If
   End Sub

   Shared Sub Main()
      Try
         Dim myStringArray(1) As String
         myStringArray.SetValue("Jones", 0)
         myStringArray.SetValue("John", 1)
         Dim myIntArray(1) As Integer
         Dim myArrayType As New ArrayTypeMisMatchConst()
         myArrayType.CopyArray(myStringArray, myIntArray)
      Catch e As ArrayTypeMismatchException
         Console.WriteLine("The Exception is :" + e.ToString())
      End Try 
   End Sub
End Class

Hinweise

Dieser Konstruktor initialisiert die Message -Eigenschaft des neuen instance zu einer vom System bereitgestellten Meldung, die den Fehler beschreibt, z. B. "Quellarraytyp kann nicht dem Zielarraytyp zugewiesen werden." Diese Nachricht berücksichtigt die aktuelle Systemkultur.

In der folgenden Tabelle werden die anfänglichen Eigenschaftenwerte für eine ArrayTypeMismatchException-Instanz aufgeführt.

Eigenschaft Wert
InnerException Ein NULL-Verweis (Nothing in Visual Basic).
Message Die lokalisierte Zeichenfolge mit der Fehlermeldung.

Gilt für:

ArrayTypeMismatchException(String)

Source:
ArrayTypeMismatchException.cs
Source:
ArrayTypeMismatchException.cs
Source:
ArrayTypeMismatchException.cs

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse mit einer angegebenen Fehlermeldung.

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

Parameter

message
String

Ein String, der den Fehler beschreibt.

Beispiele

Im folgenden Beispiel wird der ArrayTypeMismatchException(String)-Konstruktor der ArrayTypeMismatchException -Klasse veranschaulicht. Es enthält eine Funktion, die zwei Arrays als Argumente akzeptiert und überprüft, ob die beiden Arrays vom gleichen Typ sind. Wenn die Arrays unterschiedlicher Typen sind, wird ein neues ArrayTypeMismatchException ausgelöst und dann in der aufrufenden Methode abgefangen.

using namespace System;
public ref class ArrayTypeMisMatchConst
{
public:
   void CopyArray( Array^ myArray, Array^ myArray1 )
   {
      String^ typeArray1 = myArray->GetType()->ToString();
      String^ typeArray2 = myArray1->GetType()->ToString();
      
      // Check whether the two arrays are of same type or not.
      if ( typeArray1 == typeArray2 )
      {
         
         // Copies the values from one array to another.
         myArray->SetValue( String::Concat(  "Name: ", myArray1->GetValue( 0 )->ToString() ), 0 );
         myArray->SetValue( String::Concat(  "Name: ", myArray1->GetValue( 1 )->ToString() ), 1 );
      }
      else
      {
         
         // Throw an exception of type 'ArrayTypeMismatchException' with a message String* as parameter.
         throw gcnew ArrayTypeMismatchException( "The Source and destination arrays are not of same type." );
      }
   }

};

int main()
{
   try
   {
      array<String^>^myStringArray = gcnew array<String^>(2);
      myStringArray->SetValue( "Jones", 0 );
      myStringArray->SetValue( "John", 1 );
      array<Int32>^myIntArray = gcnew array<Int32>(2);
      ArrayTypeMisMatchConst^ myArrayType = gcnew ArrayTypeMisMatchConst;
      myArrayType->CopyArray( myStringArray, myIntArray );
   }
   catch ( ArrayTypeMismatchException^ e ) 
   {
      Console::WriteLine( "The Exception Message is : {0}", e->Message );
   }

}
using System;

public class ArrayTypeMismatchConst2
{
    public void CopyArray(Array myArray, Array myArray1)
    {
        string typeArray1 = myArray.GetType().ToString();
        string typeArray2 = myArray1.GetType().ToString();
        // Check whether the two arrays are of same type or not.
        if (typeArray1 == typeArray2)
        {
            // Copies the values from one array to another.
            myArray.SetValue("Name: " + myArray1.GetValue(0), 0);
            myArray.SetValue("Name: " + myArray1.GetValue(1), 1);
        }
        else
        {
            // Throw an exception of type 'ArrayTypeMismatchException' with a message string as parameter.
            throw new ArrayTypeMismatchException("The Source and destination arrays are not of same type.");
        }
    }

    static void Main()
    {
        try
        {
            string[] myStringArray = new string[2];
            myStringArray.SetValue("Jones", 0);
            myStringArray.SetValue("John", 1);
            int[] myIntArray = new int[2];
            ArrayTypeMismatchConst2 myArrayType = new();
            myArrayType.CopyArray(myStringArray, myIntArray);
        }
        catch (ArrayTypeMismatchException e)
        {
            Console.WriteLine("The Exception Message is : " + e.Message);
        }
    }
}
open System

let copyArray (myArray: Array) (myArray1: Array) =
    let typeArray1 = myArray.GetType() |> string
    let typeArray2 = myArray1.GetType() |> string
    // Check whether the two arrays are of same type or not.
    if typeArray1 = typeArray2 then
        // Copy the values from one array to another.
        myArray.SetValue($"Name: {myArray1.GetValue 0}", 0)
        myArray.SetValue($"Name: {myArray1.GetValue 1}", 1)
    else
        // Throw an exception of type 'ArrayTypeMismatchException' with a message string as parameter.
        raise (ArrayTypeMismatchException "The Source and destination arrays are not of same type.")

try
    let myStringArray = [| "Jones"; "John" |]

    let myIntArray = Array.zeroCreate<int> 2

    copyArray myStringArray myIntArray

with :? ArrayTypeMismatchException as e -> 
    printfn $"The Exception is: {e}"

Public Class ArrayTypeMisMatchConst

   Public Sub CopyArray(myArray As Array, myArray1 As Array)

      Dim typeArray1 As String = myArray.GetType().ToString()
      Dim typeArray2 As String = myArray1.GetType().ToString()
      ' Check whether the two arrays are of same type or not.
      If typeArray1 = typeArray2 Then
         ' Copies the values from one array to another.
         myArray.SetValue("Name: " + myArray1.GetValue(0), 0)
         myArray.SetValue("Name: " + myArray1.GetValue(1), 1)
      Else
         ' Throw an exception of type 'ArrayTypeMismatchException' with a message string as parameter.
         Throw New ArrayTypeMismatchException("The Source and destination arrays are not of same type.")
      End If
   End Sub
   
   Shared Sub Main()
      Try
         Dim myStringArray(1) As String
         myStringArray.SetValue("Jones", 0)
         myStringArray.SetValue("John", 1)
         Dim myIntArray(1) As Integer
         Dim myArrayType As New ArrayTypeMisMatchConst()
         myArrayType.CopyArray(myStringArray, myIntArray)
      Catch e As ArrayTypeMismatchException
         Console.WriteLine(("The Exception Message is : " + e.Message))
      End Try
   End Sub
End Class

Hinweise

Der Inhalt des message-Parameters sollte für Personen verständlich sein. Der Aufrufer dieses Konstruktors ist erforderlich, um sicherzustellen, dass diese Zeichenfolge für die aktuelle Systemkultur lokalisiert wurde.

In der folgenden Tabelle werden die anfänglichen Eigenschaftenwerte für eine ArrayTypeMismatchException-Instanz aufgeführt.

Eigenschaft Wert
InnerException Ein NULL-Verweis (Nothing in Visual Basic).
Message Die Zeichenfolge der Fehlermeldung.

Gilt für:

ArrayTypeMismatchException(SerializationInfo, StreamingContext)

Source:
ArrayTypeMismatchException.cs
Source:
ArrayTypeMismatchException.cs
Source:
ArrayTypeMismatchException.cs

Achtung

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse mit serialisierten Daten.

protected:
 ArrayTypeMismatchException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected ArrayTypeMismatchException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected ArrayTypeMismatchException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new ArrayTypeMismatchException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArrayTypeMismatchException
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new ArrayTypeMismatchException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArrayTypeMismatchException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parameter

info
SerializationInfo

Das Objekt, das die Daten des serialisierten Objekts enthält.

context
StreamingContext

Die Kontextinformationen zur Quelle bzw. zum Ziel.

Attribute

Hinweise

Dieser Konstruktor wird während der Deserialisierung aufgerufen, um das über einen Datenstrom übertragene Ausnahmeobjekt wieder zusammenzusetzen. Weitere Informationen finden Sie unter XML- und SOAP-Serialisierung.

Weitere Informationen

Gilt für:

ArrayTypeMismatchException(String, Exception)

Source:
ArrayTypeMismatchException.cs
Source:
ArrayTypeMismatchException.cs
Source:
ArrayTypeMismatchException.cs

Initialisiert eine neue Instanz der ArrayTypeMismatchException-Klasse mit einer angegebenen Fehlermeldung und einem Verweis auf die innere Ausnahme, die diese Ausnahme ausgelöst hat.

public:
 ArrayTypeMismatchException(System::String ^ message, Exception ^ innerException);
public ArrayTypeMismatchException (string message, Exception innerException);
public ArrayTypeMismatchException (string? message, Exception? innerException);
new ArrayTypeMismatchException : string * Exception -> ArrayTypeMismatchException
Public Sub New (message As String, innerException As Exception)

Parameter

message
String

Die Fehlermeldung, in der die Ursache der Ausnahme erklärt wird.

innerException
Exception

Die Ausnahme, die die Ursache der aktuellen Ausnahme ist. Wenn der innerException-Parameter kein NULL-Verweis ist, wird die aktuelle Ausnahme in einem catch-Block ausgelöst, der die innere Ausnahme behandelt.

Beispiele

Im folgenden Codebeispiel wird der ArrayTypeMismatchException Konstruktor der ArrayTypeMismatchException -Klasse veranschaulicht. Es enthält eine Funktion, die zwei Arrays als Argumente akzeptiert und überprüft, ob die beiden Arrays vom gleichen Typ sind. Wenn die Arrays unterschiedlicher Typen sind, wird ein neues ArrayTypeMismatchException ausgelöst und dann in der aufrufenden Methode abgefangen.

using namespace System;
public ref class ArrayTypeMisMatchConst
{
public:
   void CopyArray( Array^ myArray, Array^ myArray1 )
   {
      try
      {
         
         // Copies the value of one array into another array.
         myArray->SetValue( myArray1->GetValue( 0 ), 0 );
         myArray->SetValue( myArray1->GetValue( 1 ), 1 );
      }
      catch ( Exception^ e ) 
      {
         
         // Throw an exception of with a message and innerexception.
         throw gcnew ArrayTypeMismatchException( "The Source and destination arrays are of not same type.",e );
      }

   }

};

int main()
{
   try
   {
      array<String^>^myStringArray = gcnew array<String^>(2);
      myStringArray->SetValue( "Jones", 0 );
      myStringArray->SetValue( "John", 1 );
      array<Int32>^myIntArray = gcnew array<Int32>(2);
      ArrayTypeMisMatchConst^ myArrayType = gcnew ArrayTypeMisMatchConst;
      myArrayType->CopyArray( myStringArray, myIntArray );
   }
   catch ( ArrayTypeMismatchException^ e ) 
   {
      Console::WriteLine( "The Exception Message is : {0}", e->Message );
      Console::WriteLine( "The Inner exception is : {0}", e->InnerException );
   }

}
using System;

public class ArrayTypeMismatchConst3
{
    public void CopyArray(Array myArray, Array myArray1)
    {
        try
        {
            // Copies the value of one array into another array.
            myArray.SetValue(myArray1.GetValue(0), 0);
            myArray.SetValue(myArray1.GetValue(1), 1);
        }
        catch (Exception e)
        {
            // Throw an exception of with a message and innerexception.
            throw new ArrayTypeMismatchException("The Source and destination arrays are of not same type.", e);
        }
    }
    static void Main()
    {
        try
        {
            string[] myStringArray = new string[2];
            myStringArray.SetValue("Jones", 0);
            myStringArray.SetValue("John", 1);
            int[] myIntArray = new int[2];
            ArrayTypeMismatchConst3 myArrayType = new();
            myArrayType.CopyArray(myStringArray, myIntArray);
        }
        catch (ArrayTypeMismatchException e)
        {
            Console.WriteLine("The Exception Message is : " + e.Message);
            Console.WriteLine("The Inner exception is :" + e.InnerException);
        }
    }
}
open System

let copyArray (myArray: Array) (myArray1: Array) =
    try
        // Copies the value of one array into another array.
        myArray.SetValue(myArray1.GetValue 0, 0)
        myArray.SetValue(myArray1.GetValue 1, 1)

    with e ->
        // Throw an exception of with a message and innerexception.
        raise (ArrayTypeMismatchException("The Source and destination arrays are of not same type.", e))

try
    let myStringArray = [| "Jones"; "John" |]
    let myIntArray = Array.zeroCreate<int> 2
    copyArray myStringArray myIntArray

with :? ArrayTypeMismatchException as e ->
    printfn $"The Exception Message is : {e.Message}"
    printfn $"The Inner exception is: {e.InnerException}"

Public Class ArrayTypeMisMatchConst

   Public Sub CopyArray(myArray As Array, myArray1 As Array)
      Try
         ' Copies the value of one array into another array.   
         myArray.SetValue(myArray1.GetValue(0), 0)
         myArray.SetValue(myArray1.GetValue(1), 1)
      Catch e As Exception
         ' Throw an exception of type 'ArrayTypeMismatchException' with a message and innerexception.
         Throw New ArrayTypeMismatchException("The Source and destination arrays are of not same type", e)
      End Try
   End Sub

   Shared Sub Main()
      Try
         Dim myStringArray(1) As String
         myStringArray.SetValue("Jones", 0)
         myStringArray.SetValue("John", 1)
         Dim myIntArray(1) As Integer
         Dim myArrayType As New ArrayTypeMisMatchConst()
         myArrayType.CopyArray(myStringArray, myIntArray)
      Catch e As ArrayTypeMismatchException
         Console.WriteLine("The Exception Message is : " + e.Message)
         Console.WriteLine("The Inner exception is :" + e.InnerException.ToString())
      End Try
   End Sub
End Class

Hinweise

Eine Ausnahme, die als direktes Ergebnis einer vorhergehenden Ausnahme ausgelöst wird, muss in der InnerException-Eigenschaft über einen Verweis auf die vorhergehende Ausnahme verfügen. Die InnerException-Eigenschaft gibt denselben Wert zurück, der an den Konstruktor übergeben wurde, bzw. einen NULL-Verweis (Nothing in Visual Basic), wenn die InnerException-Eigenschaft nicht den Wert für die innere Ausnahme für den Konstruktor bereitstellt.

In der folgenden Tabelle werden die anfänglichen Eigenschaftenwerte für eine ArrayTypeMismatchException-Instanz aufgeführt.

Eigenschaft Wert
InnerException Der Verweis auf die interne Ausnahme.
Message Die Zeichenfolge der Fehlermeldung.

Weitere Informationen

Gilt für: