本文整理汇总了C#中System.Array.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Array.SetValue方法的具体用法?C# Array.SetValue怎么用?C# Array.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.SetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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 ) );
}
}
输出:
[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