CSharp examples for Language Basics:int
Sum two int variables
using System;/*from ww w . ja v a2 s. c o m*/ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { // 1. SOLUTION // Values to be summed int firstNumber = 42; int secondNumber = 11; // Calculating int sum = firstNumber + secondNumber; // Output Console.WriteLine("Sum is: " + sum); // 2. SOLUTION // Declaring all variables at once int thirdNumber, fourthNumber, newSum; thirdNumber = 42; fourthNumber = 11; newSum = thirdNumber + fourthNumber; Console.WriteLine("Calculated another way: " + newSum); } }