Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# error CS1061: Type `System.Collections.Generic.List<int>' does not contain a definition for `Length'

I'm programming in C# and I keep getting the error: "error CS1061: Type System.Collections.Generic.List<int>' does not contain a definition forLength' and no extension method Length' of typeSystem.Collections.Generic.List' could be found. Are you missing an assembly reference?:

I've added using System.Linq aswell, which was a solution to a number of similar problems however it still doesn't work.

 Dictionary<string, int> decryptedPossibilites = new Dictionary<string, int>();
 foreach(KeyValuePair<string, int> entry in decryptedPossibilites){
      int eCount = entry.Key.Split('E').Length - 1;
      eCountList.Add(eCount);
  }

  int temp = 0;

  for (int write = 0; write < eCountList.Length; write++){
      for (int sort = 0; sort < eCountList.Length - 1; sort++){
          if (eCountList[sort] > eCountList[sort + 1]){
              temp = eCountList[sort + 1];
              eCountList[sort + 1] = eCountList[sort];
              eCountList[sort] = temp;
            }
        }
    }

  foreach(int q in eCountList){
        Console.WriteLine(q);
  }

How can I fix this?

like image 239
Andrew1996 Avatar asked Oct 22 '25 06:10

Andrew1996


1 Answers

There is no Length property on List<T>. Use Count instead and for other classes that implement ICollection.

Length is typically only for arrays.

like image 53
vcsjones Avatar answered Oct 23 '25 20:10

vcsjones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!