Reputation: 83
I need to work with the input given by the user,how can i get the integer and char input from user and how to store it and how to use it for manipulation in c#
Upvotes: 0
Views: 11626
Reputation: 126864
Here is a simple console program that asks a user for his or her name, stores the input in a string variable, and then asks a question where the only valid response is an integer, and continues to prompt the user if an invalid input is provided. It then redisplays the user's answers on the screen.
using System;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
Console.Write("What is your name? ");
string name = Console.ReadLine();
bool validInput = false;
int inputDays = 0;
int actualDays = 7;
while (!validInput)
{
Console.Write("How many days are in a week? ");
string response = Console.ReadLine();
validInput = int.TryParse(response, out inputDays);
}
Console.WriteLine("{0}, you said there are {1} days in a week. This is {2}.", name, inputDays, inputDays == actualDays);
Console.ReadKey();
}
}
}
Upvotes: 1