Array.GetValue 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
得到當前 Array中指定元素的值。
多載
| 名稱 | Description |
|---|---|
| GetValue(Int32) |
在一維 Array空間中,得到指定位置的值。 索引會指定為32位整數。 |
| GetValue(Int32[]) |
在多維 Array空間中指定位置得到值。 索引會指定為32位整數的陣列。 |
| GetValue(Int64) |
在一維 Array空間中,得到指定位置的值。 索引會指定為64位整數。 |
| GetValue(Int64[]) |
在多維 Array空間中指定位置得到值。 索引會指定為64位整數的陣列。 |
| GetValue(Int32, Int32) |
在二維 Array中指定位置得到值。 索引會指定為32位整數。 |
| GetValue(Int64, Int64) |
在二維 Array中指定位置得到值。 索引會指定為64位整數。 |
| GetValue(Int32, Int32, Int32) |
在三維 Array空間中指定位置得到值。 索引會指定為32位整數。 |
| GetValue(Int64, Int64, Int64) |
在三維 Array空間中指定位置得到值。 索引會指定為64位整數。 |
範例
以下程式碼範例示範如何在一維或多維陣列中設定並取得特定值。
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
*/
open System
// Creates and initializes a one-dimensional array.
let myArr1 = Array.zeroCreate<string> 5
// Sets the element at index 3.
myArr1.SetValue("three", 3)
printfn $"[3]: {myArr1.GetValue 3}"
// Creates and initializes a two-dimensional array.
let myArr2 = Array2D.zeroCreate<string> 5 5
// Sets the element at index 1,3.
myArr2.SetValue("one-three", 1, 3)
printfn $"[1,3]: {myArr2.GetValue(1, 3)}"
// Creates and initializes a three-dimensional array.
let myArr3 = Array3D.zeroCreate<string> 5 5 5
// Sets the element at index 1,2,3.
myArr3.SetValue("one-two-three", 1, 2, 3)
printfn $"[1,2,3]: {myArr3.GetValue(1, 2, 3)}"
// Creates and initializes a seven-dimensional array.
let myArr7 = Array.CreateInstance(typeof<string>, 5, 5, 5, 5, 5, 5, 5)
// Sets the element at index 1,2,3,0,1,2,3.
let myIndices = [| 1; 2; 3; 0; 1; 2; 3 |]
myArr7.SetValue("one-two-three-zero-one-two-three", myIndices)
printfn $"[1,2,3,0,1,2,3]: {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
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
End Class
'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
GetValue(Int32)
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
在一維 Array空間中,得到指定位置的值。 索引會指定為32位整數。
public:
System::Object ^ GetValue(int index);
public object GetValue(int index);
public object? GetValue(int index);
member this.GetValue : int -> obj
Public Function GetValue (index As Integer) As Object
參數
傳回
在一維 Array空間中指定位置的值。
例外狀況
電流 Array 並非完全單一維度。
index 超出當前 Array有效指標範圍。
備註
與GetLowerBoundGetUpperBound方法可判定 的index值是否超出範圍。
此方法是 O(1) 作業。
另請參閱
適用於
GetValue(Int32[])
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
在多維 Array空間中指定位置得到值。 索引會指定為32位整數的陣列。
public:
System::Object ^ GetValue(... cli::array <int> ^ indices);
public object GetValue(params int[] indices);
public object? GetValue(params int[] indices);
member this.GetValue : int[] -> obj
Public Function GetValue (ParamArray indices As Integer()) As Object
參數
傳回
在多維 Array空間中指定位置的值。
例外狀況
indices 是 null。
電流 Array 中的維度數不等於 中的 indices元素數。
任何元素 indices 都不在當前 Array維度有效指標範圍內。
備註
元素 indices 數必須等於 中的 Array維度數。 陣列中 indices 的所有元素必須共同指定該元素在多維 Array空間中的位置。
GetLowerBound和 GetUpperBound 方法可以判斷是否有任何索引超出範圍。
此方法是 O(1) 作業。
另請參閱
適用於
GetValue(Int64)
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
在一維 Array空間中,得到指定位置的值。 索引會指定為64位整數。
public:
System::Object ^ GetValue(long index);
public object? GetValue(long index);
public object GetValue(long index);
[System.Runtime.InteropServices.ComVisible(false)]
public object GetValue(long index);
member this.GetValue : int64 -> obj
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.GetValue : int64 -> obj
Public Function GetValue (index As Long) As Object
參數
傳回
在一維 Array空間中指定位置的值。
- 屬性
例外狀況
電流 Array 並非完全單一維度。
index 超出當前 Array有效指標範圍。
備註
與GetLowerBoundGetUpperBound方法可判定 的index值是否超出範圍。
此方法是 O(1) 作業。
另請參閱
適用於
GetValue(Int64[])
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
在多維 Array空間中指定位置得到值。 索引會指定為64位整數的陣列。
public:
System::Object ^ GetValue(... cli::array <long> ^ indices);
public object? GetValue(params long[] indices);
public object GetValue(params long[] indices);
[System.Runtime.InteropServices.ComVisible(false)]
public object GetValue(params long[] indices);
member this.GetValue : int64[] -> obj
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.GetValue : int64[] -> obj
Public Function GetValue (ParamArray indices As Long()) As Object
參數
傳回
在多維 Array空間中指定位置的值。
- 屬性
例外狀況
indices 是 null。
電流 Array 中的維度數不等於 中的 indices元素數。
任何元素 indices 都不在當前 Array維度有效指標範圍內。
備註
元素 indices 數必須等於 中的 Array維度數。 陣列中 indices 的所有元素必須共同指定該元素在多維 Array空間中的位置。
GetLowerBound和 GetUpperBound 方法可以判斷是否有任何索引超出範圍。
此方法是 O(1) 作業。
另請參閱
適用於
GetValue(Int32, Int32)
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
在二維 Array中指定位置得到值。 索引會指定為32位整數。
public:
System::Object ^ GetValue(int index1, int index2);
public object? GetValue(int index1, int index2);
public object GetValue(int index1, int index2);
member this.GetValue : int * int -> obj
Public Function GetValue (index1 As Integer, index2 As Integer) As Object
參數
傳回
在二維 Array空間中指定位置的值。
例外狀況
電流 Array 並非完全有二維。
或 index1index2 或 都超出當前維 Array度 的有效指標範圍。
備註
GetLowerBound和 GetUpperBound 方法可以判斷是否有任何索引超出範圍。
此方法是 O(1) 作業。
另請參閱
適用於
GetValue(Int64, Int64)
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
在二維 Array中指定位置得到值。 索引會指定為64位整數。
public:
System::Object ^ GetValue(long index1, long index2);
public object? GetValue(long index1, long index2);
public object GetValue(long index1, long index2);
[System.Runtime.InteropServices.ComVisible(false)]
public object GetValue(long index1, long index2);
member this.GetValue : int64 * int64 -> obj
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.GetValue : int64 * int64 -> obj
Public Function GetValue (index1 As Long, index2 As Long) As Object
參數
傳回
在二維 Array空間中指定位置的值。
- 屬性
例外狀況
電流 Array 並非完全有二維。
或 index1index2 或 都超出當前維 Array度 的有效指標範圍。
備註
GetLowerBound和 GetUpperBound 方法可以判斷是否有任何索引超出範圍。
此方法是 O(1) 作業。
另請參閱
適用於
GetValue(Int32, Int32, Int32)
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
在三維 Array空間中指定位置得到值。 索引會指定為32位整數。
public:
System::Object ^ GetValue(int index1, int index2, int index3);
public object? GetValue(int index1, int index2, int index3);
public object GetValue(int index1, int index2, int index3);
member this.GetValue : int * int * int -> obj
Public Function GetValue (index1 As Integer, index2 As Integer, index3 As Integer) As Object
參數
傳回
在三維 Array空間中指定位置的值。
例外狀況
電流 Array 並非完全三維。
index1 或 index2 或 index3 不在當前維度 Array的有效指標範圍內。
備註
GetLowerBound和 GetUpperBound 方法可以判斷是否有任何索引超出範圍。
此方法是 O(1) 作業。
另請參閱
適用於
GetValue(Int64, Int64, Int64)
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
- 來源:
- Array.cs
在三維 Array空間中指定位置得到值。 索引會指定為64位整數。
public:
System::Object ^ GetValue(long index1, long index2, long index3);
public object? GetValue(long index1, long index2, long index3);
public object GetValue(long index1, long index2, long index3);
[System.Runtime.InteropServices.ComVisible(false)]
public object GetValue(long index1, long index2, long index3);
member this.GetValue : int64 * int64 * int64 -> obj
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.GetValue : int64 * int64 * int64 -> obj
Public Function GetValue (index1 As Long, index2 As Long, index3 As Long) As Object
參數
傳回
在三維 Array空間中指定位置的值。
- 屬性
例外狀況
電流 Array 並非完全三維。
index1 或 index2 或 index3 不在當前維度 Array的有效指標範圍內。
備註
GetLowerBound和 GetUpperBound 方法可以判斷是否有任何索引超出範圍。
此方法是 O(1) 作業。