Compiling and Executing Programs Terminology
- 
Entry Point: Code (usually a method) that's automatically run when a program is launched. In C#, this method is called 
Main(). 
Overview & Examples
Setup
Basic boilerplate setup for every C# program:
SomeFileName.csproj
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net5.0</TargetFramework>
    </PropertyGroup>
</Project>
SomeFileName.cs
using System;
class Program
{
  static void Main()
  {
    // program code goes here
  }
}
Running Programs
- We run a program with the following two steps:
- 
Compiling: In the project directory, run 
> dotnet build.FileName.csshould be the name of the file containing program code. This creates an.exefile. - 
Executing: After compiling, run the following to launch the 
.dllfile:> dotnet run. 
 - 
Compiling: In the project directory, run 
 
General Guidelines
- Files with 
.csextensions contain code written by the developer. - Files with 
.csprojextensions contain project configuration data. 
AOT Versus JIT Compiling Overview
- In modern programming languages, source code must be translated into machine code before computers can understand it. Some languages and platforms do this automatically, but others like C# must be explicitly compiled.
 
Terminology
- Compiling: Translating one type of code into another type. Generally this refers to translating a more human-readable type of code into a more complex type of code meant only for computers.
 - Just in Time: When code is compiled as a user interacts with it, as is the case with JavaScript.
 - Ahead of Time: When code is compiled ahead of time, as is the case with C#.
 
  
  
  Sample .csproj code:
DoubleIt.csproj
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net5.0</TargetFramework>
    </PropertyGroup>
</Project>
- Build a C# program with the following command: 
dotnet build. - Run a C# program with the following command: 
dotnet run. - The 
Console.WriteLine()method prints a string to the console. - The 
Console.ReadLine()method is used to retrieve input the user has typed into the command line. 
Dotnet Watcher Terminology
Watcher: Monitors files so we don't need to constantly type dotnet run. Here's how we add a watcher:
dotnet watch run
We can also do this with the build command:
dotnet watch build
              
    
Top comments (0)