ArrayTypeMismatchException Construtores
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Inicializa uma nova instância da classe ArrayTypeMismatchException.
Sobrecargas
| Nome | Description |
|---|---|
| ArrayTypeMismatchException() |
Inicializa uma nova instância da classe ArrayTypeMismatchException. |
| ArrayTypeMismatchException(String) |
Inicializa uma nova instância da ArrayTypeMismatchException classe com uma mensagem de erro especificada. |
| ArrayTypeMismatchException(SerializationInfo, StreamingContext) |
Obsoleto.
Inicializa uma nova instância da ArrayTypeMismatchException classe com dados serializados. |
| ArrayTypeMismatchException(String, Exception) |
Inicializa uma nova instância da ArrayTypeMismatchException classe com uma mensagem de erro especificada e uma referência à exceção interna que é a causa dessa exceção. |
ArrayTypeMismatchException()
Inicializa uma nova instância da classe ArrayTypeMismatchException.
public:
ArrayTypeMismatchException();
public ArrayTypeMismatchException();
Public Sub New ()
Exemplos
O exemplo a seguir demonstra o construtor ArrayTypeMismatchException() da ArrayTypeMismatchException classe. Ele contém uma função que usa duas matrizes como argumentos e verifica se as duas matrizes são do mesmo tipo. Se as matrizes forem de tipos diferentes, uma nova ArrayTypeMismatchException será lançada e, em seguida, capturada no método de chamada.
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
Comentários
Esse construtor inicializa a Message propriedade da nova instância para uma mensagem fornecida pelo sistema que descreve o erro, como "O tipo de matriz de origem não pode ser atribuído ao tipo de matriz de destino". Essa mensagem leva em conta a cultura atual do sistema.
A tabela a seguir mostra os valores de propriedade iniciais de uma instância de ArrayTypeMismatchException.
| Propriedade | Valor |
|---|---|
| InnerException | Uma referência nula (Nothing no Visual Basic). |
| Message | A cadeia de caracteres de mensagem de erro localizada. |
Aplica-se a
ArrayTypeMismatchException(String)
Inicializa uma nova instância da ArrayTypeMismatchException classe com uma mensagem de erro especificada.
public:
ArrayTypeMismatchException(System::String ^ message);
public ArrayTypeMismatchException(string message);
public ArrayTypeMismatchException(string? message);
new ArrayTypeMismatchException : string -> ArrayTypeMismatchException
Public Sub New (message As String)
Parâmetros
Exemplos
O exemplo a seguir demonstra o construtor ArrayTypeMismatchException(String) da ArrayTypeMismatchException classe. Ele contém uma função que usa duas matrizes como argumentos e verifica se as duas matrizes são do mesmo tipo. Se as matrizes forem de tipos diferentes, uma nova ArrayTypeMismatchException será lançada e, em seguida, capturada no método de chamada.
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
Comentários
O conteúdo do message parâmetro destina-se a ser compreendido por humanos. O chamador desse construtor é necessário para garantir que essa cadeia de caracteres tenha sido localizada para a cultura atual do sistema.
A tabela a seguir mostra os valores de propriedade iniciais de uma instância de ArrayTypeMismatchException.
| Propriedade | Valor |
|---|---|
| InnerException | Uma referência nula (Nothing no Visual Basic). |
| Message | A cadeia de caracteres de mensagem de erro. |
Aplica-se a
ArrayTypeMismatchException(SerializationInfo, StreamingContext)
Cuidado
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
Inicializa uma nova instância da ArrayTypeMismatchException classe com dados serializados.
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)
Parâmetros
- info
- SerializationInfo
O objeto que contém os dados do objeto serializado.
- context
- StreamingContext
As informações contextuais sobre a origem ou o destino.
- Atributos
Comentários
Esse construtor é chamado durante a desserialização para reconstituir o objeto de exceção transmitido por um fluxo. Para obter mais informações, consulte de serialização XML e SOAP.
Confira também
Aplica-se a
ArrayTypeMismatchException(String, Exception)
Inicializa uma nova instância da ArrayTypeMismatchException classe com uma mensagem de erro especificada e uma referência à exceção interna que é a causa dessa exceção.
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)
Parâmetros
- message
- String
A mensagem de erro que explica o motivo da exceção.
- innerException
- Exception
A exceção que é a causa da exceção atual. Se o innerException parâmetro não for uma referência nula, a exceção atual será gerada em um catch bloco que manipula a exceção interna.
Exemplos
O exemplo de código a seguir demonstra o ArrayTypeMismatchException construtor da ArrayTypeMismatchException classe. Ele contém uma função que usa duas matrizes como argumentos e verifica se as duas matrizes são do mesmo tipo. Se as matrizes forem de tipos diferentes, uma nova ArrayTypeMismatchException será lançada e, em seguida, capturada no método de chamada.
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
Comentários
Uma exceção gerada como resultado direto de uma exceção anterior deve incluir uma referência à exceção anterior na InnerException propriedade. A InnerException propriedade retornará o mesmo valor que é passado para o construtor ou uma referência nula (Nothing no Visual Basic) se a InnerException propriedade não fornecer o valor de exceção interna para o construtor.
A tabela a seguir mostra os valores de propriedade iniciais de uma instância de ArrayTypeMismatchException.
| Propriedade | Valor |
|---|---|
| InnerException | A referência de exceção interna. |
| Message | A cadeia de caracteres de mensagem de erro. |