ArrayTypeMismatchException Constructeurs
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe ArrayTypeMismatchException.
Surcharges
| Nom | Description |
|---|---|
| ArrayTypeMismatchException() |
Initialise une nouvelle instance de la classe ArrayTypeMismatchException. |
| ArrayTypeMismatchException(String) |
Initialise une nouvelle instance de la ArrayTypeMismatchException classe avec un message d’erreur spécifié. |
| ArrayTypeMismatchException(SerializationInfo, StreamingContext) |
Obsolète.
Initialise une nouvelle instance de la classe ArrayTypeMismatchException avec des données sérialisées. |
| ArrayTypeMismatchException(String, Exception) |
Initialise une nouvelle instance de la ArrayTypeMismatchException classe avec un message d’erreur spécifié et une référence à l’exception interne qui est la cause de cette exception. |
ArrayTypeMismatchException()
Initialise une nouvelle instance de la classe ArrayTypeMismatchException.
public:
ArrayTypeMismatchException();
public ArrayTypeMismatchException();
Public Sub New ()
Exemples
L’exemple suivant illustre le constructeur ArrayTypeMismatchException() de la ArrayTypeMismatchException classe. Il contient une fonction qui prend deux tableaux en tant qu’arguments et vérifie si les deux tableaux sont du même type. Si les tableaux sont de différents types, un nouveau ArrayTypeMismatchException est levée, puis intercepté dans la méthode appelante.
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
Remarques
Ce constructeur initialise la Message propriété de la nouvelle instance dans un message fourni par le système qui décrit l’erreur, par exemple « Le type de tableau source ne peut pas être affecté au type de tableau de destination ». Ce message prend en compte la culture système actuelle.
Le tableau suivant présente les valeurs de propriété initiales d’une instance de ArrayTypeMismatchException.
| Propriété | Valeur |
|---|---|
| InnerException | Référence Null (Nothing en Visual Basic). |
| Message | Chaîne de message d’erreur localisée. |
S’applique à
ArrayTypeMismatchException(String)
Initialise une nouvelle instance de la ArrayTypeMismatchException classe avec un message d’erreur spécifié.
public:
ArrayTypeMismatchException(System::String ^ message);
public ArrayTypeMismatchException(string message);
public ArrayTypeMismatchException(string? message);
new ArrayTypeMismatchException : string -> ArrayTypeMismatchException
Public Sub New (message As String)
Paramètres
Exemples
L’exemple suivant illustre le constructeur ArrayTypeMismatchException(String) de la ArrayTypeMismatchException classe. Il contient une fonction qui prend deux tableaux en tant qu’arguments et vérifie si les deux tableaux sont du même type. Si les tableaux sont de différents types, un nouveau ArrayTypeMismatchException est levée, puis intercepté dans la méthode appelante.
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
Remarques
Le contenu du message paramètre est destiné à être compris par les humains. L’appelant de ce constructeur est requis pour s’assurer que cette chaîne a été localisée pour la culture système actuelle.
Le tableau suivant présente les valeurs de propriété initiales d’une instance de ArrayTypeMismatchException.
| Propriété | Valeur |
|---|---|
| InnerException | Référence Null (Nothing en Visual Basic). |
| Message | Chaîne de message d’erreur. |
S’applique à
ArrayTypeMismatchException(SerializationInfo, StreamingContext)
Attention
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
Initialise une nouvelle instance de la classe ArrayTypeMismatchException avec des données sérialisées.
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)
Paramètres
- info
- SerializationInfo
Objet qui contient les données d’objet sérialisées.
- context
- StreamingContext
Informations contextuelles sur la source ou la destination.
- Attributs
Remarques
Ce constructeur est appelé lors de la désérialisation pour rétablir l’objet d’exception transmis sur un flux. Pour plus d’informations, consultez sérialisation XML et SOAP.
Voir aussi
S’applique à
ArrayTypeMismatchException(String, Exception)
Initialise une nouvelle instance de la ArrayTypeMismatchException classe avec un message d’erreur spécifié et une référence à l’exception interne qui est la cause de cette exception.
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)
Paramètres
- message
- String
Message d’erreur qui explique la raison de l’exception.
- innerException
- Exception
Exception qui est la cause de l’exception actuelle. Si le innerException paramètre n’est pas une référence Null, l’exception actuelle est levée dans un catch bloc qui gère l’exception interne.
Exemples
L’exemple de code suivant illustre le ArrayTypeMismatchException constructeur de la ArrayTypeMismatchException classe. Il contient une fonction qui prend deux tableaux en tant qu’arguments et vérifie si les deux tableaux sont du même type. Si les tableaux sont de différents types, un nouveau ArrayTypeMismatchException est levée, puis intercepté dans la méthode appelante.
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
Remarques
Une exception levée en conséquence directe d’une exception précédente doit inclure une référence à l’exception précédente dans la InnerException propriété. La InnerException propriété retourne la même valeur que celle passée au constructeur, ou une référence Null (Nothing en Visual Basic) si la InnerException propriété ne fournit pas la valeur d’exception interne au constructeur.
Le tableau suivant présente les valeurs de propriété initiales d’une instance de ArrayTypeMismatchException.
| Propriété | Valeur |
|---|---|
| InnerException | Référence d’exception interne. |
| Message | Chaîne de message d’erreur. |