See Also: ArrayTypeMismatchException Members
ArrayTypeMismatchException is thrown when the system cannot convert the element to the type declared for the array.
This exception is thrown by the Array.Copy(Array, Array, int) method if a widening conversion cannot be performed on the operand to convert it to the array type.
It is generally unnecessary for applications to throw this exception.
The following CIL instructions throw ArrayTypeMismatchException :
The following example demonstrates an error that causes the system to throw a ArrayTypeMismatchException exception.
C# Example
using System;
class ArrayTypeMisMatchExample {
public static void Main() {
string[] array1={"hello","world"};
int[] array2 = {1,2};
try {
Array.Copy(array1,array2,2);
}
catch (ArrayTypeMismatchException e) {
Console.WriteLine("Error: {0}",e);
}
}
}
The output is
Error: System.ArrayTypeMismatchException: Source array type cannot be assigned to destination array type.