C# 中数组类的 Array.Length 属性的作用是什么?
C# 中的 Array.Lenth 属性用于获取数组的长度。
我们首先设置该数组类 −
Array arr = Array.CreateInstance(typeof(String), 3);
arr.SetValue("Electronics", 0);
arr.SetValue("Clothing", 1);
arr.SetValue("Appliances", 2);由于数组的长度为 3,因此 Length 属性将生成结果 3 −
arr.Length
以下是实现数组类的 Array.Length 属性的代码 −
示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lower {
class Program {
static void Main(string[] args) {
Array arr = Array.CreateInstance(typeof(String), 3);
arr.SetValue("Electronics", 0);
arr.SetValue("Clothing", 1);
arr.SetValue("Appliances", 2);
Console.WriteLine("Length: {0}",arr.Length.ToString());
Console.ReadLine();
}
}
}输出
Length: 3
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP