C# 배열 클래스의 GetUpperBound() 메서드는 배열에 지정된 차원의 상한값을 가져옵니다.
먼저 배열을 설정하고 아래와 같이 상한값을 얻습니다. -
arr.GetUpperBound(0).ToString()
다음은 C#에서 GetUpperBound() 메서드의 사용법을 설명한 예제입니다.
예시
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("Upper Bound: {0}",arr.GetUpperBound(0).ToString());
Console.ReadLine();
}
}
} 출력
Upper Bound: 5