如何在 C# 中使用数组类的 GetUpperBound 方法?
C# 中的数组类的 GetUpperBound() 方法获取 Array 中指定维度上的上限。
首先,设置数组并获取上限,如下所示 -
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP