C# 字典 ArrayList 计数

标签 c# dictionary arraylist

是否有一种简单的方法来计算特定字典键值的值?

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/

相关文章:

java - Android 表单验证 - 如何防止空字段在按下按钮时导致应用程序崩溃?

javascript - 关闭弹出窗口

c# - Moq - 在设置的返回中使用 It.IsAny 时会发生什么?

c# - 在 bot 框架中的 c# bot 中查询自动完成

c# - 如何从用属性修饰的 C# 类生成 .proto 文件?

python - 如何在 python 中过滤和打印特定的 json 字典

java - java中的Map返回引用

powershell - Powershell 中带有元组键的字典

java - 如何格式化Java ArrayList的行和列并调用列或行的数据?

java - Java/ColdFusion 和 Lucee 之间的 identityHashCode 区别