Phương thức GetUpperBound () của lớp mảng trong C # nhận giới hạn trên của kích thước được chỉ định trong Mảng.
Đầu tiên, thiết lập mảng và lấy giới hạn trên như hình dưới đây -
arr.GetUpperBound(0).ToString()
Sau đây là một ví dụ nêu rõ việc sử dụng phương thức GetUpperBound () trong C #.
Ví dụ
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();
}
}
} Đầu ra
Upper Bound: 5