CSharp - Write program to Read Numeric Input from console window


You will read some numbers from user via the console window.

You will write a program that takes a number from the user, stores it in a numeric variable, and finally repeats it to the user.


Console.ReadLine always reads text even if what you need is a number.

To convert text to a number, use the Convert.ToInt32 method.


using System;
using System.Globalization;

class Program//from  w  ww .  j ava  2  s  . c o  m
    static void Main(string[] args)
        // Prompting the user 
        Console.Write("How old are you? ");

        // Reading line of text 
        string input = Console.ReadLine();

        // CONVERTING TO NUMBER (of entered text) 
        int enteredNumber = Convert.ToInt32(input);

        // Output of entered number 
        Console.WriteLine("Your age: " + enteredNumber);