Write a console application and implement the ternary operator to decide whether the
age a user entered after being prompted is allowed to vote or not(given that only citizens
between 18 and 120 years only inclusive can vote). Use exception handling for non-numerical
input.



Write a console application and implement the ternary operator to decide whether the age a user en..

Answer / Ajay Dangi

Here's an example in C#:

```csharp
using System;

namespace AgeValidator
{
class Program
{
static void Main(string[] args)
{
try
{
Console.Write("Enter your age: ");
string input = Console.ReadLine();
int age = Convert.ToInt32(input);

if (age >= 18 && age <= 120)
Console.WriteLine("You are eligible to vote.");
else
Console.WriteLine("You are not eligible to vote.");
}
catch (FormatException ex)
{
Console.WriteLine("Invalid input. Please enter a valid number.");
}
}
}
}
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What is the use of GC.KeepAlive Method?

1 Answers   HCL,


What are the different types of assemblies available and their purpose?

1 Answers  


What is use of list in c#?

1 Answers  


What is the meaning of MSIL?

1 Answers   TCS,


How to use delegates with events?

1 Answers  


Are there functions in c#?

1 Answers  


How do I create a dbml file?

1 Answers  


If dll and exe files are same it means you can deploy both the files in gac?

1 Answers  


What are the various components in crystal reports?

1 Answers  


How does c# achieve polymorphism?

1 Answers  


What are anonymous functions in c#?

1 Answers  


What is ispostback c#?

1 Answers  


Categories