ArrayTypeMismatchException Konstruktorok
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Inicializálja a ArrayTypeMismatchException osztály új példányát.
Túlterhelések
| Name | Description |
|---|---|
| ArrayTypeMismatchException() |
Inicializálja a ArrayTypeMismatchException osztály új példányát. |
| ArrayTypeMismatchException(String) |
Inicializálja az ArrayTypeMismatchException osztály új példányát egy megadott hibaüzenettel. |
| ArrayTypeMismatchException(SerializationInfo, StreamingContext) |
Elavult.
Inicializálja az ArrayTypeMismatchException osztály új példányát szerializált adatokkal. |
| ArrayTypeMismatchException(String, Exception) |
Inicializálja az ArrayTypeMismatchException osztály új példányát egy megadott hibaüzenettel és a kivétel okaként szolgáló belső kivételre mutató hivatkozással. |
ArrayTypeMismatchException()
Inicializálja a ArrayTypeMismatchException osztály új példányát.
public:
ArrayTypeMismatchException();
public ArrayTypeMismatchException();
Public Sub New ()
Példák
Az alábbi példa az osztály ArrayTypeMismatchException() konstruktorát ArrayTypeMismatchException mutatja be. Tartalmaz egy függvényt, amely két tömböt vesz fel argumentumként, és ellenőrzi, hogy a két tömb azonos típusú-e. Ha a tömbök különböző típusúak, a rendszer egy újat ArrayTypeMismatchException dob ki, majd a hívó metódusba kerül.
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);
}
}
}
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
Megjegyzések
Ez a konstruktor inicializálja az Message új példány tulajdonságát egy rendszer által megadott üzenetbe, amely leírja a hibát, például: "A forrástömb típusa nem rendelhető hozzá a céltömbtípushoz". Ez az üzenet figyelembe veszi a jelenlegi rendszerkultúrát.
Az alábbi táblázat a példány kezdeti tulajdonságértékét ArrayTypeMismatchExceptionmutatja be.
| Ingatlan | Érték |
|---|---|
| InnerException | Null hivatkozás (Nothing Visual Basic). |
| Message | A honosított hibaüzenet sztringje. |
A következőre érvényes:
ArrayTypeMismatchException(String)
Inicializálja az ArrayTypeMismatchException osztály új példányát egy megadott hibaüzenettel.
public:
ArrayTypeMismatchException(System::String ^ message);
public ArrayTypeMismatchException(string message);
public ArrayTypeMismatchException(string? message);
new ArrayTypeMismatchException : string -> ArrayTypeMismatchException
Public Sub New (message As String)
Paraméterek
Példák
Az alábbi példa az osztály ArrayTypeMismatchException(String) konstruktorát ArrayTypeMismatchException mutatja be. Tartalmaz egy függvényt, amely két tömböt vesz fel argumentumként, és ellenőrzi, hogy a két tömb azonos típusú-e. Ha a tömbök különböző típusúak, a rendszer egy újat ArrayTypeMismatchException dob ki, majd a hívó metódusba kerül.
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
Megjegyzések
A paraméter tartalmát message az emberek értelmezik. A konstruktor hívójának gondoskodnia kell arról, hogy ez a sztring az aktuális rendszerkultúrához legyen honosítva.
Az alábbi táblázat a példány kezdeti tulajdonságértékét ArrayTypeMismatchExceptionmutatja be.
| Ingatlan | Érték |
|---|---|
| InnerException | Null hivatkozás (Nothing Visual Basic). |
| Message | A hibaüzenet sztringje. |
A következőre érvényes:
ArrayTypeMismatchException(SerializationInfo, StreamingContext)
Figyelemfelhívás
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
Inicializálja az ArrayTypeMismatchException osztály új példányát szerializált adatokkal.
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éterek
- info
- SerializationInfo
A szerializált objektumadatokat tartalmazó objektum.
- context
- StreamingContext
A forrásra vagy a célra vonatkozó környezeti információk.
- Attribútumok
Megjegyzések
Ezt a konstruktort a deszerializálás során hívjuk meg a streamen keresztül továbbított kivételobjektum újbóli létrehozásához. További információ: XML- és SOAP-szerializálás.
Lásd még
A következőre érvényes:
ArrayTypeMismatchException(String, Exception)
Inicializálja az ArrayTypeMismatchException osztály új példányát egy megadott hibaüzenettel és a kivétel okaként szolgáló belső kivételre mutató hivatkozással.
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éterek
- message
- String
A kivétel okát magyarázó hibaüzenet.
- innerException
- Exception
Az aktuális kivétel okaként megadott kivétel. Ha a innerException paraméter nem null értékű hivatkozás, a rendszer az aktuális kivételt a catch belső kivételt kezelő blokkban emeli ki.
Példák
Az alábbi példakód az ArrayTypeMismatchException osztály konstruktorát ArrayTypeMismatchException mutatja be. Olyan függvényt tartalmaz, amely argumentumként két tömböt vesz fel, és ellenőrzi, hogy a két tömb azonos típusú-e. Ha a tömbök különböző típusúak, a rendszer egy újat ArrayTypeMismatchException dob ki, majd a hívó metódusba kerül.
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
Megjegyzések
Az előző kivétel közvetlen eredményeként keletkező kivételnek tartalmaznia kell a tulajdonság előző kivételére InnerException mutató hivatkozást. A InnerException tulajdonság ugyanazt az értéket adja vissza, amelyet a konstruktornak ad át, vagy nullhivatkozást (Nothing Visual Basic), ha a InnerException tulajdonság nem adja meg a belső kivétel értékét a konstruktornak.
Az alábbi táblázat a példány kezdeti tulajdonságértékét ArrayTypeMismatchExceptionmutatja be.
| Ingatlan | Érték |
|---|---|
| InnerException | A belső kivételre mutató hivatkozás. |
| Message | A hibaüzenet sztringje. |