I was solving a problem which says that I have to take a character input and print it's ascii value.
I wrote a program like this which works fine.
using System;
namespace ASCII_Value
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int i = Convert.ToInt32(s[0]);
Console.WriteLine(i);
}
}
}
But is there a better way that I only take a character input because user can enter a sentence and will get ascii value of the first character which is senseless as it is stated in the problem statement that I should take in a character.
I want that user not to be able to enter more than one character.