This chapter introduces getting started with C# coding to meet the following objectives:
(i) First Example CodeBefore You Start If you are absolute beginner please watch the provided video links from Microsoft Virtual Academy Lectures by Instructor | Bob Tabor – Microsoft MVP. The tutorials explains which software to download to start coding and running the programs in C# programming language.
Begin with Traditioal Hello World! program
//Example Listing 2.1 using System; namespace QSSTraining { class Program { public static void Main(string[] args) { Console.Write("Hello World!"); } } }
//Example Listing 2.1 using System; namespace QSSTraining { class Program { public static void Main(string[] args) { Console.Write("Welcome to C# .NET Programming World!"); } } }
Note:The System.Console.ReadLine()method will cause the application to pause until the user presses the Enter key.
ReadLine method example code
//Example Listing 2.2 //ReadLine.cs using System; namespace QSSTraining { class Program { public static void Main(string[] args) { Console.Write("Hello World!"); Console.ReadLine(); } } }
Basic Console Input/Output Methods
Input Methods
Read: The Read method reads the next character from the keyboard.
ReadLine: The ReadLine method reads all characters up to the end of
the input line (the carriage return character).
Output Methods
Basic Console Output Methods: (1)Write and (2)WriteLine
Write: Writes the specified information to the standard output stream.
WriteLine: Writes the specified data, followed by the current line
terminator, to the standard output stream.
//Example Listing 2.3 using System; namespace QSSTraining { class Program { public static void Main(string[] args) { Console.Write("Please enter First Name: "); string firstName = Console.ReadLine(); Console.Write("Please enter Last Name: "); string lastName = Console.ReadLine(); Console.Write("You entered "); Console.WriteLine("First Name = {0} Last Name = {1}", firstName, lastName); Console.Read(); } } }