日期:2014-05-17  浏览次数:20876 次

麻烦大家告诉一下我怎么去获取list<>的长度
   List<string> a = new List<string>();

            int i = 0;
            while (true)
            {
                a.Add(Console.ReadLine());

                string c = a[i];

                if (c == "")
                    break;
                i++;
            }
想问一下,怎么去表示a的长度,我用a.length貌似不能获取

------解决方案--------------------
try this:

List<string> a = new List<string>();

int i = 0;
while (i<10)
{
    a.Add(i.ToString());
    i++;
}
Console.ReadLine(a.Length);

------解决方案--------------------
Count属性
------解决方案--------------------
List<string> a = new List<string>();
string s = "";
while (true)
{
    s = Console.ReadLine();
    if (s == "") break;
    a.Add(s);
}
------解决方案--------------------
a.Count
------解决方案--------------------
a.Count()可以获取 这个是LINQ方式获取--这个是Linq
a.Count也可以获取 这个是集合的长度属性--这个是属性