Page 62 - CSharp/C#
P. 62

(Always use descriptive names for projects so that they can easily be distinguished from
              other projects. It is recommended not to use spaces in project or class name.)


            7.  Write code. You can now update your Program.cs to present "Hello world!" to the user.


               using System;

               namespace ConsoleApplication1
               {
                   public class Program
                   {
                       public static void Main(string[] args)
                       {
                       }
                   }
               }


              Add the following two lines to the public static void Main(string[] args) object in Program.cs:
              (make sure it's inside the braces)

              : (make sure it's inside the braces)


               Console.WriteLine("Hello world!");
               Console.Read();


              Why Console.Read()? The first line prints out the text "Hello world!" to the console, and the
              second line waits for a single character to be entered; in effect, this causes the program to
              pause execution so that you're able to see the output while debugging. Without
              Console.Read();, when you start debugging the application it will just print "Hello world!" to the
              console and then immediately close. Your code window should now look like the following:


               using System;

               namespace ConsoleApplication1
               {
                   public class Program
                   {
                       public static void Main(string[] args)
                       {
                           Console.WriteLine("Hello world!");
                           Console.Read();
                       }
                   }
               }


            8.  Debug your program. Press the Start Button on the toolbar near the top of the window

                         or press F5 on your keyboard to run your application. If the button is not present,
              you can run the program from the top menu: Debug → Start Debugging. The program will
              compile and then open a console window. It should look similar to the following screenshot:









        https://riptutorial.com/                                                                                8
   57   58   59   60   61   62   63   64   65   66   67