我如何确定我的 C# 数组的长度
首先,设置一个数组 -
int[] arr = {6, 3, 8, 4};
现在,使用 Length 属性获取数组的长度 -
arr.Length
让我们看看完整的代码 -
示例
using System; namespace Demo { public class Demo { public static void Main(string[] args) { int[] arr = {6, 3, 8, 4}; Console.WriteLine("Array..."); foreach (int i in arr) { Console.Write(i + " "); } Console.WriteLine("
Size of Array: "+arr.Length); } } }
输出
Array... 6 3 8 4 Size of Array: 4
广告