有几个属性List<T>
似乎与列表中的项目数相关 - Capacity
,Count
(作为属性和方法存在).与Array
刚刚 相比,这非常令人困惑Length
.
我正在使用,List.Capacity
但它给出了意想不到的结果:
List <string> fruits = new List<string>();
fruits.Add("apple");
fruits.Add("orange");
fruits.Add("banana");
fruits.Add("cherry");
fruits.Add("mango");
Console.WriteLine("the List has {0} items in it.", fruits.Capacity);
Run Code Online (Sandbox Code Playgroud)
当我运行此控制台时,控制台显示:
the List has 4 items in it.
我不明白为什么它显示Capacity
8,当我只添加5项.
if ((file.Exists) ?
lblresults.Text = "the file is there" :
lblresults.Text = "the file is not there");
Run Code Online (Sandbox Code Playgroud)
我一直得到错误说明不能隐含地将字符串转换为bool
任何帮助都会很棒,谢谢.