ArrayTypeMismatchException Constructor (String)
Initializes a new instance of the ArrayTypeMismatchException class with a specified error message.
Assembly: mscorlib (in mscorlib.dll)
The content of the message parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
The following table shows the initial property values for an instance of ArrayTypeMismatchException.
Property | Value |
|---|---|
A null reference (Nothing in Visual Basic). | |
The error message string. |
The following example demonstrates the ArrayTypeMismatchException(String) constructor of the ArrayTypeMismatchException class. It contains a function which takes two arrays as arguments and checks whether the two arrays are of the same type. If the arrays are of different types, a new ArrayTypeMismatchException is thrown and then caught in the calling method.
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 ); } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.