Addition of two number read from console - CSharp Language Basics

CSharp examples for Language Basics:Console

Description

Addition of two number read from console

Demo Code

using System;// w  w  w . j  a va2s.  c  om
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Input of 1. number
      Console.Write("Enter 1. number: ");
      string input1 = Console.ReadLine();
      int number1 = Convert.ToInt32(input1);
      // Input of 2. number
      Console.Write("Enter 2. number: ");
      string input2 = Console.ReadLine();
      int number2 = Convert.ToInt32(input2);
      // Calculating
      int result = number1 + number2;
      // Result output
      Console.WriteLine("Sum of entered numbers is: " + result);
   }
}

Result


Related Tutorials