次の方法で共有


Array.GetValue メソッド (Int64 )

メモ : この名前空間、クラス、およびメンバは、.NET Framework Version 1.1 だけでサポートされています。

多次元 Array 内の指定した位置にある値を取得します。インデックスは 64 ビット整数値の配列として指定します。

<ComVisible(False)>
Overloads Public Function GetValue( _   ByVal ParamArray indices() As Long _) As Object
[C#]
[ComVisible(false)]
public object GetValue(   params long[] indices);
[C++]
[ComVisible(false)]
public: Object* GetValue(__int64indices __gc[]);
[JScript]
public
   ComVisible(false)
function GetValue(indices : long[]) : Object;

パラメータ

  • indices
    取得する Array 要素の位置を指定するインデックスを表す 64 ビット整数の 1 次元配列。

戻り値

多次元 Array 内の指定した位置にある値。

例外

例外の種類 条件
ArgumentNullException indices が null 参照 (Visual Basic では Nothing) です。
ArgumentException 現在の Array 内の次元数が、 indices 内の要素数と等しくありません。
IndexOutOfRangeException indices 内のいずれかの要素が、現在の Array の対応する次元にとって有効なインデックス範囲の外にあります。

解説

indices 内の要素数が、 Array 内の次元数と等しい必要があります。 indices 配列内のすべての要素をまとめた全体で、多次元の Array 内にある目的の要素の位置が指定されている必要があります。

GetLowerBound メソッドと GetUpperBound メソッドを使用して、範囲外のインデックスがあるかどうかを確認します。

使用例

[Visual Basic, C#, C++] 1 次元配列または多次元配列の特定の値を設定および取得する方法を次のコード例に示します。

 
Imports System

Public Class SamplesArray

   Public Shared Sub Main()

      ' Creates and initializes a one-dimensional array.
      Dim myArr1(4) As [String]

      ' Sets the element at index 3.
      myArr1.SetValue("three", 3)
      Console.WriteLine("[3]:   {0}", myArr1.GetValue(3))


      ' Creates and initializes a two-dimensional array.
      Dim myArr2(5, 5) As [String]

      ' Sets the element at index 1,3.
      myArr2.SetValue("one-three", 1, 3)
      Console.WriteLine("[1,3]:   {0}", myArr2.GetValue(1, 3))


      ' Creates and initializes a three-dimensional array.
      Dim myArr3(5, 5, 5) As [String]

      ' Sets the element at index 1,2,3.
      myArr3.SetValue("one-two-three", 1, 2, 3)
      Console.WriteLine("[1,2,3]:   {0}", myArr3.GetValue(1, 2, 3))


      ' Creates and initializes a seven-dimensional array.
      Dim myArr7(5, 5, 5, 5, 5, 5, 5) As [String]

      ' Sets the element at index 1,2,3,0,1,2,3.
      Dim myIndices() As Integer = {1, 2, 3, 0, 1, 2, 3}
      myArr7.SetValue("one-two-three-zero-one-two-three", myIndices)
      Console.WriteLine("[1,2,3,0,1,2,3]:   {0}", myArr7.GetValue(myIndices))

   End Sub 'Main 

End Class 'SamplesArray


'This code produces the following output.
'
'[3]:   three
'[1,3]:   one-three
'[1,2,3]:   one-two-three
'[1,2,3,0,1,2,3]:   one-two-three-zero-one-two-three


[C#] 
using System;

public class SamplesArray  {

   public static void Main()  {
 
      // Creates and initializes a one-dimensional array.
      String[] myArr1 = new String[5];

      // Sets the element at index 3.
      myArr1.SetValue( "three", 3 );
      Console.WriteLine( "[3]:   {0}", myArr1.GetValue( 3 ) );


      // Creates and initializes a two-dimensional array.
      String[,] myArr2 = new String[5,5];

      // Sets the element at index 1,3.
      myArr2.SetValue( "one-three", 1, 3 );
      Console.WriteLine( "[1,3]:   {0}", myArr2.GetValue( 1, 3 ) );


      // Creates and initializes a three-dimensional array.
      String[,,] myArr3 = new String[5,5,5];

      // Sets the element at index 1,2,3.
      myArr3.SetValue( "one-two-three", 1, 2, 3 );
      Console.WriteLine( "[1,2,3]:   {0}", myArr3.GetValue( 1, 2, 3 ) );


      // Creates and initializes a seven-dimensional array.
      String[,,,,,,] myArr7 = new String[5,5,5,5,5,5,5];

      // Sets the element at index 1,2,3,0,1,2,3.
      int[] myIndices = new int[7] { 1, 2, 3, 0, 1, 2, 3 };
      myArr7.SetValue( "one-two-three-zero-one-two-three", myIndices );
      Console.WriteLine( "[1,2,3,0,1,2,3]:   {0}", myArr7.GetValue( myIndices ) );

   }
 
}


/* 
This code produces the following output.

[3]:   three
[1,3]:   one-three
[1,2,3]:   one-two-three
[1,2,3,0,1,2,3]:   one-two-three-zero-one-two-three

*/


[C++] 
#using <mscorlib.dll>
using namespace System;

int main()  {
 
      // Creates and initializes a one-dimensional array.
      String* myArr1[] = new String*[5];

      // Sets the element at index 3.
      myArr1->SetValue( S"three", 3 );
      Console::WriteLine( S"[3]:   {0}", myArr1->GetValue( 3 ) );


      // Creates and initializes a two-dimensional array.
      String* myArr2[,] = new String*[5,5];

      // Sets the element at index 1,3.
      myArr2->SetValue( S"one-three", 1, 3 );
      Console::WriteLine( S"[1,3]:   {0}", myArr2->GetValue( 1, 3 ) );


      // Creates and initializes a three-dimensional array.
      String* myArr3[,,] = new String*[5,5,5];

      // Sets the element at index 1,2,3.
      myArr3->SetValue( S"one-two-three", 1, 2, 3 );
      Console::WriteLine( S"[1,2,3]:   {0}", myArr3->GetValue( 1, 2, 3 ) );


      // Creates and initializes a seven-dimensional array.
      String* myArr7[,,,,,,] = new String*[5,5,5,5,5,5,5];

      // Sets the element at index 1,2,3,0,1,2,3.
      Int32 myIndices[] = { 1, 2, 3, 0, 1, 2, 3 };
      myArr7->SetValue( S"one-two-three-zero-one-two-three", myIndices);
      Console::WriteLine( S"[1,2,3,0,1,2,3]:   {0}", myArr7->GetValue( myIndices ) );

}


/* 
This code produces the following output.

[3]:   three
[1,3]:   one-three
[1,2,3]:   one-two-three
[1,2,3,0,1,2,3]:   one-two-three-zero-one-two-three

*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Array クラス | Array メンバ | System 名前空間 | Array.GetValue オーバーロードの一覧 | GetLowerBound | GetUpperBound | SetValue