Udostępnij za pośrednictwem


ArrayTypeMismatchException Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy ArrayTypeMismatchException.

Przeciążenia

Nazwa Opis
ArrayTypeMismatchException()

Inicjuje nowe wystąpienie klasy ArrayTypeMismatchException.

ArrayTypeMismatchException(String)

Inicjuje nowe wystąpienie ArrayTypeMismatchException klasy z określonym komunikatem o błędzie.

ArrayTypeMismatchException(SerializationInfo, StreamingContext)
Przestarzałe.

Inicjuje ArrayTypeMismatchException nowe wystąpienie klasy z serializowanymi danymi.

ArrayTypeMismatchException(String, Exception)

Inicjuje nowe wystąpienie ArrayTypeMismatchException klasy z określonym komunikatem o błędzie i odwołaniem do wyjątku wewnętrznego, który jest przyczyną tego wyjątku.

ArrayTypeMismatchException()

Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs

Inicjuje nowe wystąpienie klasy ArrayTypeMismatchException.

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

Przykłady

W poniższym przykładzie pokazano konstruktor ArrayTypeMismatchException ArrayTypeMismatchException() klasy . Zawiera funkcję, która przyjmuje dwie tablice jako argumenty i sprawdza, czy dwie tablice są tego samego typu. Jeśli tablice mają różne typy, zostanie zgłoszony nowy ArrayTypeMismatchException , a następnie przechwycony w metodzie wywołującej.

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

Uwagi

Ten konstruktor inicjuje Message właściwość nowego wystąpienia do komunikatu dostarczonego przez system, który opisuje błąd, taki jak "Typ tablicy źródłowej nie może być przypisany do typu tablicy docelowej". Ten komunikat uwzględnia bieżącą kulturę systemu.

W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia ArrayTypeMismatchExceptionklasy .

Majątek Wartość
InnerException Odwołanie o wartości null (Nothing w Visual Basic).
Message Zlokalizowany ciąg komunikatu o błędzie.

Dotyczy

ArrayTypeMismatchException(String)

Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs

Inicjuje nowe wystąpienie ArrayTypeMismatchException klasy z określonym komunikatem o błędzie.

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

String opisujący błąd.

Przykłady

W poniższym przykładzie pokazano konstruktor ArrayTypeMismatchException ArrayTypeMismatchException(String) klasy . Zawiera funkcję, która przyjmuje dwie tablice jako argumenty i sprawdza, czy dwie tablice są tego samego typu. Jeśli tablice mają różne typy, zostanie zgłoszony nowy ArrayTypeMismatchException , a następnie przechwycony w metodzie wywołującej.

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

Uwagi

Zawartość parametru message ma być rozumiana przez ludzi. Obiekt wywołujący tego konstruktora jest wymagany, aby upewnić się, że ten ciąg został zlokalizowany dla bieżącej kultury systemu.

W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia ArrayTypeMismatchExceptionklasy .

Majątek Wartość
InnerException Odwołanie o wartości null (Nothing w Visual Basic).
Message Ciąg komunikatu o błędzie.

Dotyczy

ArrayTypeMismatchException(SerializationInfo, StreamingContext)

Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs

Uwaga

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

Inicjuje ArrayTypeMismatchException nowe wystąpienie klasy z serializowanymi danymi.

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

Obiekt, który przechowuje serializowane dane obiektu.

context
StreamingContext

Kontekstowe informacje o źródle lub miejscu docelowym.

Atrybuty

Uwagi

Ten konstruktor jest wywoływany podczas deserializacji w celu ponownego utworzenia obiektu wyjątku przesyłanego przez strumień. Aby uzyskać więcej informacji, zobacz Serializacja XML i SOAP.

Zobacz też

Dotyczy

ArrayTypeMismatchException(String, Exception)

Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs
Źródło:
ArrayTypeMismatchException.cs

Inicjuje nowe wystąpienie ArrayTypeMismatchException klasy z określonym komunikatem o błędzie i odwołaniem do wyjątku wewnętrznego, który jest przyczyną tego wyjątku.

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

Komunikat o błędzie wyjaśniający przyczynę wyjątku.

innerException
Exception

Wyjątek, który jest przyczyną bieżącego wyjątku. innerException Jeśli parametr nie jest odwołaniem o wartości null, bieżący wyjątek jest zgłaszany w catch bloku, który obsługuje wyjątek wewnętrzny.

Przykłady

W poniższym przykładzie kodu pokazano ArrayTypeMismatchException konstruktor ArrayTypeMismatchException klasy . Zawiera funkcję, która przyjmuje dwie tablice jako argumenty i sprawdza, czy dwie tablice są tego samego typu. Jeśli tablice mają różne typy, zostanie zgłoszony nowy ArrayTypeMismatchException , a następnie przechwycony w metodzie wywołującej.

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

Uwagi

Wyjątek zgłaszany bezpośrednio w wyniku poprzedniego wyjątku powinien zawierać odwołanie do poprzedniego wyjątku InnerException we właściwości . Właściwość InnerException zwraca tę samą wartość, która jest przekazywana do konstruktora lub odwołanie o wartości null (Nothing w Visual Basic), jeśli InnerException właściwość nie dostarcza wartości wyjątku wewnętrznego do konstruktora.

W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia ArrayTypeMismatchExceptionklasy .

Majątek Wartość
InnerException Odwołanie do wyjątku wewnętrznego.
Message Ciąg komunikatu o błędzie.

Zobacz też

Dotyczy