Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Dictionary ArrayList Count

Is there an easy way to get a count on the values of a specific dictionarys keys values?

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;
}
like image 767
Akers Avatar asked Dec 21 '22 13:12

Akers


1 Answers

I haven't tested it, but this should be close to what you need.

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;
  }
}
like image 155
Rex Morgan Avatar answered Jan 06 '23 02:01

Rex Morgan