Getting error “CS0246: The type or namespace name 'List<>' could not be found” when trying to declare a list for storing numbers

|▌冷眼眸甩不掉的悲伤 提交于 2020-03-06 09:22:31

问题


I'm new to C# comming from a python background. I'm currently trying to solve this challenge on codewars.com. It's about finding all the divisors to a number. I tried programming the following way

public class Kata
{  
  public static int[] Divisors(int n)
  {
    List<int> divisors = new List<int>();
    int i = 2, biggest_divisor = n;
    while (true)
    {
      if ( n % i == 0)
        {
          divisors.add(i);
          divisors.add(n/i);
          biggest_divisor = i;
        }
      if ( i > biggest_divisor)
        break;
      i++;
    }
    return divisors;
  }
}

I get this error however

error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)

I looked at other questions refering to this error aswell but that didn't solve my problem. For instance I tried declaring the list as public static.

来源:https://stackoverflow.com/questions/60391439/getting-error-cs0246-the-type-or-namespace-name-list-could-not-be-found-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!