System.RankException Class

The exception that is thrown when an array with the wrong number of dimensions is passed to a method.

See Also: RankException Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public class RankException : SystemException

Remarks

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.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Example

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()
 

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0