Prime Number Formula

前端 未结 13 1644
情话喂你
情话喂你 2020-12-06 08:47

I am trying to write a prime number function in C# and I am wondering if the follow code will work. It \"appears\" to work with the first 50 numbers or so. I just want to ma

13条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 09:34

    It had to be done...

    public static bool IsPrime(this int number)
    {
        return (Enumerable.Range(1,number).Where(x => number % x == 0).Count() == 2);
    }
    

提交回复
热议问题