是否有一种简单的方法来计算特定字典键值的值?
static void Main()
{
Dictionary<string, ArrayList> SpecTimes = new Dictionary<string, ArrayList>;
ArrayList times = new ArrayList();
string count = "";
times.Add = "000.00.00";
times.Add = "000.00.00";
times.Add = "000.00.00";
string spec = "A101";
SpecTimes.Add(spec,times);
count = SpecTimes[spec].values.count;
}
最佳答案
我还没有测试过,但这应该接近您的需要。
static void Main()
{
Dictionary<string, List<string>> SpecTimes = new Dictionary<string, List<string>>();
List<string> times = new List<string>();
int count = 0;
times.Add = "000.00.00";
times.Add = "000.00.00";
times.Add = "000.00.00";
string spec = "A101";
SpecTimes.Add(spec,times);
// check to make sure the key exists, otherwise you'll get an exception.
if(SpecTimes.ContainsKey(spec))
{
count = SpecTimes[spec].Count;
}
}
关于C# 字典 ArrayList 计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6060748/