Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ArrayTypeMismatchException Constructor

.NET Framework 1.1

Initializes a new instance of the ArrayTypeMismatchException class.

Overload List

Initializes a new instance of the ArrayTypeMismatchException class.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New()
[C#] public ArrayTypeMismatchException();
[C++] public: ArrayTypeMismatchException();
[JScript] public function ArrayTypeMismatchException();

Initializes a new instance of the ArrayTypeMismatchException class with a specified error message.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(String)
[C#] public ArrayTypeMismatchException(string);
[C++] public: ArrayTypeMismatchException(String*);
[JScript] public function ArrayTypeMismatchException(String);

Initializes a new instance of the ArrayTypeMismatchException class with serialized data.

[Visual Basic] Protected Sub New(SerializationInfo, StreamingContext)
[C#] protected ArrayTypeMismatchException(SerializationInfo, StreamingContext);
[C++] protected: ArrayTypeMismatchException(SerializationInfo*, StreamingContext);
[JScript] protected function ArrayTypeMismatchException(SerializationInfo, StreamingContext);

Initializes a new instance of the ArrayTypeMismatchException class with a specified error message and a reference to the inner exception that is the cause of this exception.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(String, Exception)
[C#] public ArrayTypeMismatchException(string, Exception);
[C++] public: ArrayTypeMismatchException(String*, Exception*);
[JScript] public function ArrayTypeMismatchException(String, Exception);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the ArrayTypeMismatchException constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 

Imports System

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 'CopyArray

   Shared Sub Main()
      Try
         Dim myStringArray(2) As String
         myStringArray.SetValue("Jones", 0)
         myStringArray.SetValue("John", 1)
         Dim myIntArray(2) 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 'Main
End Class 'ArrayTypeMisMatchConst

[C#] 

using System;

public 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 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];
            ArrayTypeMisMatchConst myArrayType = new ArrayTypeMisMatchConst();
            myArrayType.CopyArray(myStringArray,myIntArray);
         }
         catch(ArrayTypeMismatchException e)
         {
            Console.WriteLine("The Exception Message is : "+e.Message);
            Console.WriteLine("The Inner exception is :"+e.InnerException);
         }
      }
}

[C++] 

#using <mscorlib.dll>

using namespace System;

public __gc 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 new ArrayTypeMismatchException(S"The Source and destination arrays are of not same type.", e);
      }

   }
};

int main()
{
   try {
      String* myStringArray[] = new String*[2];
      myStringArray->SetValue(S"Jones", 0);
      myStringArray->SetValue(S"John", 1);
      Int32 myIntArray[] = new Int32[2];
      ArrayTypeMisMatchConst* myArrayType = new ArrayTypeMisMatchConst();
      myArrayType->CopyArray(myStringArray, myIntArray);
   } catch (ArrayTypeMismatchException* e) {
      Console::WriteLine(S"The Exception Message is : {0}", e->Message);
      Console::WriteLine(S"The Inner exception is : {0}", e->InnerException);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ArrayTypeMismatchException Class | ArrayTypeMismatchException Members | System Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.