C# Function to check Prime Number

What is Prime Number?

A prime number is a number that is greater than 1 and can be divided only by 1 and itself.

For ex. 3, 5, 7… are  prime numbers.


  1. Because they are greater than 1 And
  2. They can be divided only by 1 and itself.

But, 4,6,8,….are not prime numbers, because they don’t follow the two rules given above.


How to find a Prime Number in C#?

public static bool IsPrimeNumber(int number)
    int i;
    for (i = 2; i < number; i++)
        if (number % i == 0)
            return false;

    return (i == number);


Deepak Arora

Deepak Arora is a Software Developer and working continuously in this field from 2011. He work mainly with Microsoft Technology. He holds a Master's in Computer Application and he is MCTS certified person.

Leave a Reply

Your email address will not be published. Required fields are marked *