ArrayTypeMismatchException Costruttori

Definizione

Inizializza una nuova istanza della classe ArrayTypeMismatchException.

Overload

ArrayTypeMismatchException()

Inizializza una nuova istanza della classe ArrayTypeMismatchException.

ArrayTypeMismatchException(String)

Inizializza una nuova istanza della classe ArrayTypeMismatchException con un messaggio di errore specificato.

ArrayTypeMismatchException(SerializationInfo, StreamingContext)
Obsoleti.

Inizializza una nuova istanza della classe ArrayTypeMismatchException con dati serializzati.

ArrayTypeMismatchException(String, Exception)

Inizializza una nuova istanza della classe ArrayTypeMismatchException con un messaggio di errore specificato e un riferimento all'eccezione interna che è la causa dell'eccezione corrente.

ArrayTypeMismatchException()

Inizializza una nuova istanza della classe ArrayTypeMismatchException.

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

Esempio

Nell'esempio seguente viene illustrato il costruttore ArrayTypeMismatchException() della ArrayTypeMismatchException classe. Contiene una funzione che accetta due matrici come argomenti e verifica se le due matrici sono dello stesso tipo. Se le matrici sono di tipi diversi, viene generata una nuova ArrayTypeMismatchException e quindi rilevata nel metodo chiamante.

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

Commenti

Questo costruttore inizializza la proprietà della nuova istanza a un messaggio fornito dal sistema che descrive l'errore Message , ad esempio "Il tipo di matrice di origine non può essere assegnato al tipo di matrice di destinazione". Questo messaggio tiene conto delle impostazioni cultura di sistema correnti.

Nella tabella seguente vengono illustrati i valori di proprietà iniziali per un'istanza di ArrayTypeMismatchException.

Proprietà valore
InnerException Riferimento null (Nothing in Visual Basic).
Message Stringa del messaggio di errore localizzato.

Si applica a

ArrayTypeMismatchException(String)

Inizializza una nuova istanza della classe ArrayTypeMismatchException con un messaggio di errore specificato.

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

Parametri

message
String

String che descrive l'errore.

Esempio

Nell'esempio seguente viene illustrato il costruttore ArrayTypeMismatchException(String) della ArrayTypeMismatchException classe. Contiene una funzione che accetta due matrici come argomenti e verifica se le due matrici sono dello stesso tipo. Se le matrici sono di tipi diversi, viene generata una nuova ArrayTypeMismatchException e quindi rilevata nel metodo chiamante.

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

Commenti

Il contenuto del parametro message deve essere facilmente comprensibile. Il chiamante di questo costruttore è necessario per assicurarsi che questa stringa sia stata localizzata per le impostazioni cultura correnti del sistema.

Nella tabella seguente vengono illustrati i valori di proprietà iniziali per un'istanza di ArrayTypeMismatchException.

Proprietà valore
InnerException Riferimento null (Nothing in Visual Basic).
Message Stringa del messaggio di errore.

Si applica a

ArrayTypeMismatchException(SerializationInfo, StreamingContext)

Attenzione

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

Inizializza una nuova istanza della classe ArrayTypeMismatchException con dati serializzati.

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)

Parametri

info
SerializationInfo

Oggetto che contiene i dati oggetto serializzati.

context
StreamingContext

Informazioni contestuali sull'origine o sulla destinazione.

Attributi

Commenti

Questo costruttore viene chiamato durante la deserializzazione per ricostituire l'oggetto dell'eccezione trasmesso tramite un flusso. Per altre informazioni, vedere Serializzazione XML e SOAP.

Vedi anche

Si applica a

ArrayTypeMismatchException(String, Exception)

Inizializza una nuova istanza della classe ArrayTypeMismatchException con un messaggio di errore specificato e un riferimento all'eccezione interna che è la causa dell'eccezione corrente.

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)

Parametri

message
String

Messaggio di errore in cui viene indicato il motivo dell'eccezione.

innerException
Exception

Eccezione che ha determinato l'eccezione corrente. Se il parametro innerException non è un riferimento Null, l'eccezione corrente verrà generata in un blocco catch che gestisce l'eccezione interna.

Esempio

Nell'esempio di codice seguente viene illustrato il ArrayTypeMismatchException costruttore della ArrayTypeMismatchException classe. Contiene una funzione che accetta due matrici come argomenti e verifica se le due matrici sono dello stesso tipo. Se le matrici sono di tipi diversi, viene generata una nuova ArrayTypeMismatchException e quindi rilevata nel metodo chiamante.

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

Commenti

Un'eccezione generata come risultato diretto di un'eccezione precedente deve includere un riferimento all'eccezione precedente nella proprietà InnerException. La proprietà InnerException restituisce lo stesso valore che viene passato al costruttore o un riferimento null (Nothing in Visual Basic), se la proprietà InnerException non fornisce al costruttore il valore dell'eccezione interna.

Nella tabella seguente vengono illustrati i valori di proprietà iniziali per un'istanza di ArrayTypeMismatchException.

Proprietà Valore
InnerException Riferimento all'eccezione interna.
Message Stringa del messaggio di errore.

Vedi anche

Si applica a