ArrayTypeMismatchException Constructors

Definitie

Initialiseert een nieuw exemplaar van de ArrayTypeMismatchException klasse.

Overloads

Name Description
ArrayTypeMismatchException()

Initialiseert een nieuw exemplaar van de ArrayTypeMismatchException klasse.

ArrayTypeMismatchException(String)

Initialiseert een nieuw exemplaar van de ArrayTypeMismatchException klasse met een opgegeven foutbericht.

ArrayTypeMismatchException(SerializationInfo, StreamingContext)

Initialiseert een nieuw exemplaar van de ArrayTypeMismatchException klasse met geserialiseerde gegevens.

ArrayTypeMismatchException(String, Exception)

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

ArrayTypeMismatchException()

Initialiseert een nieuw exemplaar van de ArrayTypeMismatchException klasse.

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

Voorbeelden

In het volgende voorbeeld ziet u de constructor ArrayTypeMismatchException() van de ArrayTypeMismatchException klasse. Het bevat een functie die twee matrices als argumenten gebruikt en controleert of de twee matrices van hetzelfde type zijn. Als de matrices van verschillende typen zijn, wordt er een nieuwe ArrayTypeMismatchException gegenereerd en vervolgens gevangen in de aanroepmethode.

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

Opmerkingen

Met deze constructor wordt de Message eigenschap van het nieuwe exemplaar geïnitialiseerd naar een door het systeem opgegeven bericht waarin de fout wordt beschreven, zoals 'Bronmatrixtype kan niet worden toegewezen aan het doelmatrixtype'. Dit bericht houdt rekening met de huidige systeemcultuur.

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

Property Value
InnerException Een null-verwijzing (Nothing in Visual Basic).
Message De gelokaliseerde foutberichttekenreeks.

Van toepassing op

ArrayTypeMismatchException(String)

Initialiseert een nieuw exemplaar van de ArrayTypeMismatchException klasse met een opgegeven foutbericht.

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

Parameters

message
String

Een String die de fout beschrijft.

Voorbeelden

In het volgende voorbeeld ziet u de constructor ArrayTypeMismatchException(String) van de ArrayTypeMismatchException klasse. Het bevat een functie die twee matrices als argumenten gebruikt en controleert of de twee matrices van hetzelfde type zijn. Als de matrices van verschillende typen zijn, wordt er een nieuwe ArrayTypeMismatchException gegenereerd en vervolgens gevangen in de aanroepmethode.

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

Opmerkingen

De inhoud van de message parameter is bedoeld om door mensen te worden begrepen. De aanroeper van deze constructor is vereist om ervoor te zorgen dat deze tekenreeks is gelokaliseerd voor de huidige systeemcultuur.

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

Property Value
InnerException Een null-verwijzing (Nothing in Visual Basic).
Message De tekenreeks van het foutbericht.

Van toepassing op

ArrayTypeMismatchException(SerializationInfo, StreamingContext)

Initialiseert een nieuw exemplaar van de ArrayTypeMismatchException klasse met geserialiseerde gegevens.

protected:
 ArrayTypeMismatchException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected ArrayTypeMismatchException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new ArrayTypeMismatchException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArrayTypeMismatchException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parameters

info
SerializationInfo

Het object met de geserialiseerde objectgegevens.

context
StreamingContext

De contextuele informatie over de bron of bestemming.

Opmerkingen

Deze constructor wordt aangeroepen tijdens deserialisatie om het uitzonderingsobject te reconstitueren dat via een stroom wordt verzonden. Zie XML- en SOAP-serialisatie voor meer informatie.

Zie ook

Van toepassing op

ArrayTypeMismatchException(String, Exception)

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

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

Parameters

message
String

In het foutbericht wordt de reden voor de uitzondering uitgelegd.

innerException
Exception

De uitzondering die de oorzaak is van de huidige uitzondering. Als de innerException parameter geen null-verwijzing is, wordt de huidige uitzondering gegenereerd in een catch blok dat de binnenste uitzondering afhandelt.

Voorbeelden

In het volgende codevoorbeeld ziet u de ArrayTypeMismatchException constructor van de ArrayTypeMismatchException klasse. Het bevat een functie die twee matrices als argumenten gebruikt en controleert of de twee matrices van hetzelfde type zijn. Als de matrices van verschillende typen zijn, wordt er een nieuwe ArrayTypeMismatchException gegenereerd en vervolgens gevangen in de aanroepmethode.

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

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 eigenschap InnerException retourneert dezelfde waarde die wordt doorgegeven aan de constructor of een null-verwijzing (Nothing in Visual Basic) als de eigenschap InnerException de interne uitzonderingswaarde niet aan de constructor levert.

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

Property Value
InnerException De interne uitzonderingsreferentie.
Message De tekenreeks van het foutbericht.

Zie ook

Van toepassing op