CSharp - Write program to check a set of possible values

Requirements

The user enters a grade of a student.

You will check then whether the entered number is in the set of possible values 1, 2, 3, 4, or 5.

Hint

The if condition can be used to enumerate the individual alternatives.

Demo

using System;
class Program/*from ww  w.  j  a v  a 2  s .c o  m*/
{
    static void Main(string[] args)
    {
        // Input 
        Console.Write("Enter a grade: ");
        string input = Console.ReadLine();
        int grade = Convert.ToInt32(input);

        // Evaluating 
        if (grade == 1 ||
            grade == 2 ||
            grade == 3 ||
            grade == 4 ||
            grade == 5)
        {
            Console.WriteLine("Input OK.");
        }
        else
        {
            Console.WriteLine("Incorrect input.");
        }
    }
}

Result

The following code solves the exercise using a range check.

Demo

using System;
class Program/* w w  w . j av  a2s. c om*/
{
    static void Main(string[] args)
    {
        // Input 
        Console.Write("Enter a grade: ");
        string input = Console.ReadLine();
        int grade = Convert.ToInt32(input);
        // Evaluating 
        if (grade >= 1 && grade <= 5)
        {
            Console.WriteLine("Input OK.");
        }
        else
        {
            Console.WriteLine("Incorrect input.");
        }
    }
}

Result