C# Program to check the age of a user is eligible for voting or not


In this program, You will learn how to check the age of a user who is eligible for voting or not in C#.


if( age >= 18 ) { 
   //statement
}

Example: How to check the age of a user is eligible for voting or not in C#.

using System;
public class Test
{
	public static void Main(string[] args)
	{
		int age;
		Console.Write("Enter age of a user:");
		age = Convert.ToInt32(Console.ReadLine());

		if (age >= 18)
		{
			Console.WriteLine("User is valid for voting:" + age);
		}
		else
		{
			Console.WriteLine("User is not valid for voting:" + age);
		}

	}
}

Output:

Enter age of a user:40
User is valid for voting:40