SetValue() 메서드는 1차원 배열의 지정된 위치에 있는 요소에 값을 설정합니다. 인덱스는 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