在C#一个未知长度的数组 [英] Array of an unknown length in C#

查看:1896
本文介绍了在C#一个未知长度的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习C#和在介绍阵列他们表现如何建立一个变量作为一个数组,但似乎人们必须在分配指定数组的长度,所以如果我不知道是什么数组长度?

I've just started learning C# and in the introduction to arrays they showed how to establish a variable as an array but is seems that one must specify the length of the array at assignment, so what if I don't know the length of the array?

推荐答案

数组必须分配的长度。为了允许任意数量的元素,使用 列表 类。

Arrays must be assigned a length. To allow for any number of elements, use the List class.

例如:

List<int> myInts = new List<int>();
myInts.Add(5);
myInts.Add(10);
myInts.Add(11);
myInts.Count // = 3

这篇关于在C#一个未知长度的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆