Source Code
Code below is a fragment taken from
Bits Repository.
You can download the repo containing code for all Bits by opening the "Code" dropdown
in that page.
// See https://aka.ms/new-console-template for more information
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello C# World");
}
}
}
Output
This is output from the C# source code above, running in Visual Studio Code. The output is retrieved
in an embedded terminal window. VS Code runs on Windows, Linux, and macOS.
C:\github\JimFawcett\Bits\CSharp\Cs_Hello
> dotnet run
Hello C# World
C:\github\JimFawcett\Bits\CSharp\Cs_Hello
Build
To build a project with dotnet you use two commands, dotnet build to build
and dotnet run to build and run the project. dotnet is a command line application
provided as part of a Visual Studio (Community Edition) installation.
C:\github\JimFawcett\Bits\CSharp\Cs_Hello
> dotnet build
MSBuild version 17.4.1+fedecea9d for .NET
Determining projects to restore...
All projects are up-to-date for restore.
Cs_Hello -> C:\github\JimFawcett\Bits\CSharp\Cs_Hell
o\bin\Debug\net7.0\Cs_Hello.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.75
C:\github\JimFawcett\Bits\CSharp\Cs_Hello
>
Create Project
The terminal session below shows how to create a project for C#
with dotnet infrastructure. See tooling information here:
Bits_Tooling.
C:\github\JimFawcett\test
> dotnet new console -n CSharp_Hello
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring C:\github\JimFawcett\test\CSharp_Hello\CSharp_Hello.csproj:
Determining projects to restore...
Restored C:\github\JimFawcett\test\CSharp_Hello\CSharp_Hello.csproj (in 50 ms).
Restore succeeded.
C:\github\JimFawcett\test
> cd CSharp_Hello
C:\github\JimFawcett\test\CSharp_Hello
> dir
Directory: C:\github\JimFawcett\test\CSharp_Hello
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/24/2023 9:41 AM obj
-a---- 2/24/2023 9:41 AM 249 CSharp_Hello.csproj
-a---- 2/24/2023 9:41 AM 105 Program.cs
C:\github\JimFawcett\test\CSharp_Hello
>