简体   繁体   中英

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 for Length' and no extension method Length' of type System.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?

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

Length is typically only for arrays.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM