Sdílet prostřednictvím


ArrayTypeMismatchException Konstruktory

Definice

Inicializuje novou instanci ArrayTypeMismatchException třídy.

Přetížení

Name Description
ArrayTypeMismatchException()

Inicializuje novou instanci ArrayTypeMismatchException třídy.

ArrayTypeMismatchException(String)

Inicializuje novou instanci ArrayTypeMismatchException třídy se zadanou chybovou zprávou.

ArrayTypeMismatchException(SerializationInfo, StreamingContext)
Zastaralé.

Inicializuje novou instanci ArrayTypeMismatchException třídy serializovanými daty.

ArrayTypeMismatchException(String, Exception)

Inicializuje novou instanci ArrayTypeMismatchException třídy se zadanou chybovou zprávou a odkazem na vnitřní výjimku, která je příčinou této výjimky.

ArrayTypeMismatchException()

Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs

Inicializuje novou instanci ArrayTypeMismatchException třídy.

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

Příklady

Následující příklad ukazuje ArrayTypeMismatchException() konstruktor ArrayTypeMismatchException třídy. Obsahuje funkci, která jako argumenty přebírá dvě pole a kontroluje, zda jsou obě matice stejného typu. Pokud jsou pole různých typů, je vyvolána nová ArrayTypeMismatchException a poté zachycena ve volající metodě.

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

Poznámky

Tento konstruktor inicializuje Message vlastnost nové instance do zprávy zadané systémem, která popisuje chybu, jako je například Typ zdrojového pole nelze přiřadit cílovému typu pole. Tato zpráva bere v úvahu aktuální systémovou jazykovou verzi.

V následující tabulce jsou uvedeny počáteční hodnoty vlastností instance ArrayTypeMismatchException.

Vlastnictví Hodnota
InnerException Odkaz null (Nothing v jazyce Visual Basic).
Message Lokalizovaný řetězec chybové zprávy.

Platí pro

ArrayTypeMismatchException(String)

Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs

Inicializuje novou instanci ArrayTypeMismatchException třídy se zadanou chybovou zprávou.

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

Parametry

message
String

A String , který popisuje chybu.

Příklady

Následující příklad ukazuje ArrayTypeMismatchException(String) konstruktor ArrayTypeMismatchException třídy. Obsahuje funkci, která jako argumenty přebírá dvě pole a kontroluje, zda jsou obě matice stejného typu. Pokud jsou pole různých typů, je vyvolána nová ArrayTypeMismatchException a poté zachycena ve volající metodě.

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

Poznámky

Obsah parametru message má být srozumitelný lidmi. Volající tohoto konstruktoru je nutný k zajištění toho, aby byl tento řetězec lokalizován pro aktuální systémovou jazykovou verzi.

V následující tabulce jsou uvedeny počáteční hodnoty vlastností instance ArrayTypeMismatchException.

Vlastnictví Hodnota
InnerException Odkaz null (Nothing v jazyce Visual Basic).
Message Řetězec chybové zprávy.

Platí pro

ArrayTypeMismatchException(SerializationInfo, StreamingContext)

Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs

Upozornění

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

Inicializuje novou instanci ArrayTypeMismatchException třídy serializovanými daty.

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);
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}")>]
new ArrayTypeMismatchException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArrayTypeMismatchException
new ArrayTypeMismatchException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArrayTypeMismatchException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parametry

info
SerializationInfo

Objekt, který obsahuje serializovaná data objektu.

context
StreamingContext

Kontextové informace o zdroji nebo cíli.

Atributy

Poznámky

Tento konstruktor je volána během deserializace k rekonstituci objekt výjimky přenášený přes datový proud. Další informace naleznete v tématu XML a SOAP Serializace.

Viz také

Platí pro

ArrayTypeMismatchException(String, Exception)

Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs
Zdroj:
ArrayTypeMismatchException.cs

Inicializuje novou instanci ArrayTypeMismatchException třídy se zadanou chybovou zprávou a odkazem na vnitřní výjimku, která je příčinou této výjimky.

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)

Parametry

message
String

Chybová zpráva, která vysvětluje důvod výjimky.

innerException
Exception

Výjimka, která je příčinou aktuální výjimky. innerException Pokud parametr není odkazem null, aktuální výjimka je vyvolána v catch bloku, který zpracovává vnitřní výjimku.

Příklady

Následující příklad kódu ukazuje ArrayTypeMismatchException konstruktor ArrayTypeMismatchException třídy. Obsahuje funkci, která jako argumenty přebírá dvě pole a kontroluje, zda jsou dvě pole stejného typu. Pokud jsou pole různých typů, je vyvolána nová ArrayTypeMismatchException a poté zachycena ve volající metodě.

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

Poznámky

Výjimka, která je vyvolán jako přímý výsledek předchozí výjimky by měla obsahovat odkaz na předchozí výjimku ve InnerException vlastnosti. Vlastnost InnerException vrátí stejnou hodnotu, která je předána do konstruktoru, nebo null odkaz (Nothing v jazyce Visual Basic), pokud InnerException vlastnost neposkytuje vnitřní hodnotu výjimky konstruktoru.

V následující tabulce jsou uvedeny počáteční hodnoty vlastností instance ArrayTypeMismatchException.

Vlastnictví Hodnota
InnerException Odkaz na vnitřní výjimku.
Message Řetězec chybové zprávy.

Viz také

Platí pro