ArrayTypeMismatchException 생성자

정의

ArrayTypeMismatchException 클래스의 새 인스턴스를 초기화합니다.

오버로드

ArrayTypeMismatchException()

ArrayTypeMismatchException 클래스의 새 인스턴스를 초기화합니다.

ArrayTypeMismatchException(String)

지정된 오류 메시지를 사용하여 ArrayTypeMismatchException 클래스의 새 인스턴스를 초기화합니다.

ArrayTypeMismatchException(SerializationInfo, StreamingContext)
사용되지 않음.

serialize된 데이터를 사용하여 ArrayTypeMismatchException 클래스의 새 인스턴스를 초기화합니다.

ArrayTypeMismatchException(String, Exception)

지정된 오류 메시지와 해당 예외의 원인인 내부 예외에 대한 참조를 사용하여 ArrayTypeMismatchException 클래스의 새 인스턴스를 초기화합니다.

ArrayTypeMismatchException()

ArrayTypeMismatchException 클래스의 새 인스턴스를 초기화합니다.

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

예제

다음 예제에서는 클래스의 ArrayTypeMismatchException() 생성자를 보여 줍니다 ArrayTypeMismatchException . 두 배열을 인수로 사용하고 두 배열이 동일한 형식인지 여부를 확인하는 함수를 포함합니다. 배열이 다른 형식인 경우 새 ArrayTypeMismatchException 가 throw된 다음 호출 메서드에서 catch됩니다.

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

설명

이 생성자는 새 instance 속성을 "원본 배열 형식을 대상 배열 형식에 할당할 수 없습니다."와 같은 오류를 설명하는 시스템 제공 메시지로 초기화 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)

매개 변수

message
String

오류를 설명하는 String입니다.

예제

다음 예제에서는 클래스의 ArrayTypeMismatchException(String) 생성자를 보여 줍니다 ArrayTypeMismatchException . 두 배열을 인수로 사용하고 두 배열이 동일한 형식인지 여부를 확인하는 함수를 포함합니다. 배열이 다른 형식인 경우 새 ArrayTypeMismatchException 가 throw된 다음 호출 메서드에서 catch됩니다.

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

설명

message 매개 변수의 내용은 사용자가 이해할 수 있도록 만들어졌습니다. 현재 시스템 culture에 대해 이 문자열이 지역화되었는지 확인하려면 이 생성자의 호출자가 필요합니다.

다음 표에는 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.

serialize된 데이터를 사용하여 ArrayTypeMismatchException 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

info
SerializationInfo

serialize된 개체 데이터를 보유하는 개체입니다.

context
StreamingContext

원본 또는 대상에 대한 컨텍스트 정보입니다.

특성

설명

이 생성자는 스트림을 통해 전송되는 예외 개체를 다시 구성하기 위해 역직렬화 중에 호출됩니다. 자세한 내용은 XML 및 SOAP Serialization합니다.

추가 정보

적용 대상

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 . 두 배열을 인수로 사용하고 두 배열이 동일한 형식인지 여부를 확인하는 함수를 포함합니다. 배열이 다른 형식인 경우 새 ArrayTypeMismatchException 가 throw된 다음 호출 메서드에서 catch됩니다.

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

설명

이전 예외의 직접적인 결과로 throw되는 예외의 InnerException 속성에는 이전 예외에 대한 참조가 들어 있어야 합니다. InnerException 속성은 생성자에 전달된 값과 같은 값을 반환하거나 Nothing 속성이 생성자에 내부 예외 값을 제공하지 않는 경우에는 null 참조(Visual Basic의 경우 InnerException)를 반환합니다.

다음 표에는 ArrayTypeMismatchException의 인스턴스의 초기 속성 값이 나와 있습니다.

속성
InnerException 내부 예외 참조
Message 오류 메시지 문자열입니다.

추가 정보

적용 대상