Converting To Number (Of Entered Text) - CSharp Language Basics

CSharp examples for Language Basics:Data Type Cast

Description

Converting To Number (Of Entered Text)

Demo Code

using System;//from   w ww.j a v a2s  . c o  m
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   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);
   }
}

Result


Related Tutorials