The exception that is thrown when an array with the wrong number of dimensions is passed to a method.
See Also: RankException Members
RankException uses the HRESULT COR_E_RANK, that has the value 0x80131517.
For a list of initial property values for an instance of RankException, see the RankException.#ctor constructors.
The following example demonstrates an error that causes a RankException exception.
C# Example
using System; public class RankExample { public static void Main() { int[] oneDAry = new int[5]; int[,] twoDAry = new int[2,3]; for (int i = 0; i < 2; i++ ) { oneDAry.SetValue( i, i ); } try { Array.Copy( oneDAry, twoDAry, 2); } catch ( RankException e ) { Console.WriteLine( "Error caught: {0}", e ); } } }
The output is
Example
Error caught: System.RankException: The specified arrays must have the same number of dimensions. at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length) at System.Array.Copy(Array sourceArray, Array destinationArray, Int32 length) at RankExample.Main()