C# Program to Add Two Integers

In this program, you'll learn to store and add two integer numbers in C#. After addition, the final sum is displayed on the screen.

C# Program to Add Two Integers

// C# program to add two numbers
using System;
// namespace declaration
namespace App {
    class AddTwoNumbers
    	static void Main(String[] args)
    		Console.WriteLine("Enter two numbers");
    		var first = 10;
    		var second = 20;
    		Console.WriteLine(first.ToString() + " " + second.ToString());
    		// add two numbers
    		var sum = first + second;
    		Console.WriteLine("The sum is: " + sum.ToString());


Enter two numbers

10 20

The sum is: 30
In this program, two integers 10 and 20 are stored in variables first and second respectively.

Then, the first and second are added using the + operator, and its result is stored in another variable sum.

Finally, the sum is printed on the screen using Console.WriteLine() method.

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course