如何在 C# 中使用 array 类的 SetValue(,) 方法?
SetValue() 方法设置一维 Array 中指定位置处的元素值。索引指定为一个 32 位整数。
首先,设置数组。
Array arr = Array.CreateInstance(typeof(String), 6);
不使用 SetValue() 方法为元素设置值。
arr.SetValue("One", 0);
arr.SetValue("Two", 1);
arr.SetValue("Three", 3);
arr.SetValue("Four", 4);
arr.SetValue("Five", 5);以下是一个显示在 C# 中使用 SetValue() 方法的示例。
示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class Program {
static void Main(string[] args) {
Array arr = Array.CreateInstance(typeof(String), 6);
arr.SetValue("One", 0);
arr.SetValue("Two", 1);
arr.SetValue("Three", 3);
arr.SetValue("Four", 4);
arr.SetValue("Five", 5);
Console.WriteLine("Length {0}",arr.GetLength(0).ToString());
Console.ReadLine();
}
}
}输出
Length 6
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP