ArrayTypeMismatchException コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。
オーバーロード
| 名前 | 説明 |
|---|---|
| ArrayTypeMismatchException() |
ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。 |
| ArrayTypeMismatchException(String) |
指定したエラー メッセージを使用して、 ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。 |
| ArrayTypeMismatchException(SerializationInfo, StreamingContext) |
古い.
シリアル化されたデータを使用して、 ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。 |
| ArrayTypeMismatchException(String, Exception) |
指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、 ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。 |
ArrayTypeMismatchException()
ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。
public:
ArrayTypeMismatchException();
public ArrayTypeMismatchException();
Public Sub New ()
例
次の例では、 ArrayTypeMismatchException クラスの ArrayTypeMismatchException() コンストラクターを示します。 これには、2 つの配列を引数として受け取り、2 つの配列が同じ型であるかどうかを確認する関数が含まれています。 配列の型が異なる場合は、新しい ArrayTypeMismatchException がスローされ、呼び出し元のメソッドでキャッチされます。
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
注釈
このコンストラクターは、新しいインスタンスの Message プロパティを、"ソース配列型をコピー先の配列型に割り当てることができない" などのエラーを説明するシステム指定のメッセージに初期化します。このメッセージでは、現在のシステム カルチャが考慮されます。
次の表に、 ArrayTypeMismatchExceptionのインスタンスの初期プロパティ値を示します。
| 財産 | 価値 |
|---|---|
| InnerException | null 参照 (Visual Basic のNothing )。 |
| Message | ローカライズされたエラー メッセージ文字列。 |
適用対象
ArrayTypeMismatchException(String)
指定したエラー メッセージを使用して、 ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。
public:
ArrayTypeMismatchException(System::String ^ message);
public ArrayTypeMismatchException(string message);
public ArrayTypeMismatchException(string? message);
new ArrayTypeMismatchException : string -> ArrayTypeMismatchException
Public Sub New (message As String)
パラメーター
例
次の例は、 ArrayTypeMismatchException クラスの ArrayTypeMismatchException(String) コンストラクターを示しています。 これには、2 つの配列を引数として受け取り、2 つの配列が同じ型であるかどうかを確認する関数が含まれています。 配列の型が異なる場合は、新しい ArrayTypeMismatchException がスローされ、呼び出し元のメソッドでキャッチされます。
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
注釈
messageパラメーターの内容は、人間が理解することを意図しています。 このコンストラクターの呼び出し元は、この文字列が現在のシステム カルチャ用にローカライズされていることを確認する必要があります。
次の表に、 ArrayTypeMismatchExceptionのインスタンスの初期プロパティ値を示します。
| 財産 | 価値 |
|---|---|
| InnerException | null 参照 (Visual Basic のNothing )。 |
| Message | エラー メッセージ文字列。 |
適用対象
ArrayTypeMismatchException(SerializationInfo, StreamingContext)
注意事項
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
シリアル化されたデータを使用して、 ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。
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)
パラメーター
- info
- SerializationInfo
シリアル化されたオブジェクト データを保持するオブジェクト。
- context
- StreamingContext
ソースまたは変換先に関するコンテキスト情報。
- 属性
注釈
このコンストラクターは、ストリーム経由で送信される例外オブジェクトを再構成するために、逆シリアル化中に呼び出されます。 詳細については、「 XML および SOAP シリアル化」を参照してください。
こちらもご覧ください
適用対象
ArrayTypeMismatchException(String, Exception)
指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、 ArrayTypeMismatchException クラスの新しいインスタンスを初期化します。
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)
パラメーター
- message
- String
例外の理由を説明するエラー メッセージ。
- innerException
- Exception
現在の例外の原因である例外。
innerException パラメーターが null 参照でない場合、内部例外を処理するcatch ブロックで現在の例外が発生します。
例
次のコード例は、ArrayTypeMismatchException クラスのArrayTypeMismatchException コンストラクターを示しています。 2 つの配列を引数として受け取り、2 つの配列が同じ型であるかどうかを確認する関数が含まれています。 配列の型が異なる場合は、新しい ArrayTypeMismatchException がスローされ、呼び出し元のメソッドでキャッチされます。
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
注釈
前の例外の直接の結果としてスローされる例外は、 InnerException プロパティに前の例外への参照を含める必要があります。
InnerException プロパティは、コンストラクターに渡されるのと同じ値を返します。InnerException プロパティがコンストラクターに内部例外値を提供しない場合は null 参照 (Visual Basic でNothing)。
次の表に、 ArrayTypeMismatchExceptionのインスタンスの初期プロパティ値を示します。
| 財産 | 価値 |
|---|---|
| InnerException | 内部例外参照。 |
| Message | エラー メッセージ文字列。 |