2. • Console is nothing but static class only. In the console applications. we can
the i/p that o/p will displayed in the command prompt.
• It supports cui(character user interface) ,console supports 4 types of
methods.
• 1.write()-o/p
• 2.writeLine()-o/p with new line
• 3.Read()-read the values(i/p)
• 4.ReadLine()-i/p with new line
• syntax:
• using system;
• namespace namespacename
• { class classname
• { statements; }
• static void Main(string[] args)
• { statements; }}
3. Add two numbers:
1.open visual studio 2012-4.5
2.file-new -project-visual c#-console application-ok
• compile code:
• using System;
• namespace addtwonumbers
• { class Program
• { static void Main(string[] args)
• { int a, b, c;
• a = 100;
• b = 200;
• c = a + b;
• Console.WriteLine("the value c is:" + c.ToString());
• Console.ReadLine();
• } }}
4. • compilation : build-build solution-.exe
• execution: go to debug-start debugging
• Above example converts into oops:
• using System;
• namespace addtwonumbers
• { class abc//class
• { int a, b, c;//variables
• public void add()//method
• { Console.WriteLine("enter a value");
• a = int.Parse(Console.ReadLine());//type casting string converts into int
• Console.WriteLine("enter b value");
• b = int.Parse(Console.ReadLine());//type casting string converts into int
• c = a + b;
5. • Console.WriteLine("the value c is:" + c.ToString());
• Console.ReadLine(); }
• static void Main(string[] args)
• { abc obj = new abc();//instance variable
• obj.add();//calling the method } }}
• note:
• strint[] args is the command line args.
• it is collection of homogeneous datatypes.in this every value is based on index
number.index starts from 0 onwards..
• o/p:
• Console.WriteLine("the value of a,b,c is:{0},{1},{2}" ,a,b, c.ToString());
6. For more visit our website www.siri-kt.blogspot.com
Thanks for
Watching
More Angular JS TutorialsMore C sharp (c#) tutorials