C Sharp Console Application and sample program of Addition of two integers
Download and Open the Visual Studio(Any version. I am using Visual studio ultimate 2012). - Click on the new Project
- A Window will appear giving you all types of templates and project you can create.
- Select the console Application from the list.
- Then at the bottom of windows,there will be three lines , Name location and solution name.
- Enter the name for your application and browse the location where you want to save it.
- solution name will be same as your Application name.
- After giving name, just click on Ok Button.
- Your Project will be created.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello C Sharp");
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello C Sharp");
}
}
}
Output
Hello C Sharp
Hello C Sharp
using System;
namespace addint
{
class Program
{
static void Main(string[] args)
{
int a;
int b;
int res;
Console.WriteLine("Enter the first number to add");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number to add");
b = Convert.ToInt32(Console.ReadLine());
res = a + b;
Console.WriteLine("Addition of two integers " +a+ " and "+b+ " is " +res);
Console.ReadKey();
}
}
}
namespace addint
{
class Program
{
static void Main(string[] args)
{
int a;
int b;
int res;
Console.WriteLine("Enter the first number to add");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number to add");
b = Convert.ToInt32(Console.ReadLine());
res = a + b;
Console.WriteLine("Addition of two integers " +a+ " and "+b+ " is " +res);
Console.ReadKey();
}
}
}
Output
Enter the first number to add
2
Enter the second number to add
3
Addition of two integers 2 and 3 is 5
2
Enter the second number to add
3
Addition of two integers 2 and 3 is 5
Using System:- System is the namespace which contains all the required classes and libraries which are useful to write most of the basic programs.
namespace addint:- This namespace is the user defined namespace in which the above program is written.
class program:-class is the keyword defining the class to be used and the Program is the name of the class.
static void main(String [] args):- main() method which is the entry point of Console Application. This is the method where program starts executing. The Strings Array is passed to this method. This Array is used for interacting with Command Line Arguments.
There are three variables declared 'a', 'b' and 'res' for storing two values for adding and third is for storing result of addition.
And Finally the addition is printed on Console.
C Sharp Console Application and sample program of Addition of two integers
Reviewed by LanguageExpert
on
August 10, 2017
Rating:
No comments