Page 64 - CSharp/C#
P. 64

mcs -out:HelloWorld.exe HelloWorld.cs


        The resulting HelloWorld.exe can then be executed with:


         mono HelloWorld.exe


        which will produce the output:


         Hello, world!
         Press any key to exit..


        Creating a new program using .NET Core


        First install the .NET Core SDK by going through the installation instructions for the platform of
        your choice:


            •  Windows
            •  OSX
            •  Linux
            •  Docker

        After the installation has completed, open a command prompt, or terminal window.


            1.  Create a new directory with mkdir hello_world and change into the newly created directory
              with cd hello_world.

            2.  Create a new console application with dotnet new console.
              This will produce two files:


                  •  hello_world.csproj


                     <Project Sdk="Microsoft.NET.Sdk">

                       <PropertyGroup>
                         <OutputType>Exe</OutputType>
                         <TargetFramework>netcoreapp1.1</TargetFramework>
                       </PropertyGroup>

                     </Project>


                  •  Program.cs


                     using System;

                     namespace hello_world
                     {
                         class Program
                         {
                             static void Main(string[] args)
                             {
                                 Console.WriteLine("Hello World!");




        https://riptutorial.com/                                                                               10
   59   60   61   62   63   64   65   66   67   68   69