.NET Core and C#

Lab 1

A little bit about me 

Hi, I am Lukas and I will be your tutor this semester.

I am a software architect, long time .NET developer, front end developer and also data scientiest. 

I am here to help you learn C# and start developing under the .NET platform.

How is this lab different?

  • We will cover a different implementation of .NET than other groups
  • This implementation is newer, more performant and open-source
  • Sometimes our lab content will be bit different
  • You will have to learn more stuff than the other groups because we have more features to cover and you still have to learn not only new version but also old implementation from lectures.

slide was left intentionally blank

Requirements

  • Bullet One
  • Bullet Two
  • Bullet Three

slide was left intentionally blank

Let's dive into .NET platform

What version of .NET choose

Use .NET Core for your server application when:

  • You have cross-platform needs.
  • You are targeting microservices.
  • You are using Docker containers.
  • You need high-performance and scalable systems.
  • You need side-by-side .NET versions per application.
  • Windows, macOS, and Linux support .NET Core.

Use .NET Framework for your server application when:

  • Your app currently uses .NET Framework (recommendation is to extend instead of migrating).
  • Your app uses third-party .NET libraries or NuGet packages not available for .NET Core.
  • Your app uses .NET technologies that aren't available for .NET Core.
  • Your app uses a platform that doesn’t support .NET Core.

JIT compilation

Most of .NET Core is using JIT compilation.

 JITs are well suited for long-running scenarios. They generate code that targets a specific machine configuration, including specific CPU instructions.

A JIT can also re-generate methods at runtime to achieve a highly-tuned version of the frequently used method.

AOT Compilation

MONO is using LLVM to do AOT compilation. The same is for Blazor Framework.

The goal of .NET 5 is to use AOT compilation in most cases but use JIT in cases where AOT performance is not great (= generics).

AOT provides fast startup, low footprint, and lower memory usage

Common Intermediate Language (aka CIL)

  • Language integration (multiple languages generate nearly the same instructions.
  • Platform agnostic code

Common type system (aka CTS)

The .NET Core Runtime (CoreCLR)

This is the base library for .NET Core. It includes the garbage collector, JIT compiler, base .NET types, and many of the low-level classes. The runtime provides the bridge between the .NET Core framework libraries (CoreFX) and the underlying operating systems.

The Framework Libraries (CoreFX)

This is the set of .NET Core foundational libraries and includes classes for collections, file systems, the console, XML, async, and many other base items. These libraries build on CoreCLR and provide the interface points for other frameworks into the runtime. 

Review of some questions related to classes

  • What is sealed class?
  • Abstract or concrete?
  • What is the visibility of this class?
  • What are interfaces?
  • Interface vs abstract class?

Review of some questions related to OOP

 
  • What is polymorphism?
  • What is abstraction?
  • What is encapsulation?
  • What is visibility?

Let's start with some team building activity

And not let's do some real coding

.NET CLI

 
dotnet new -l
dotnet new console
dotnet build
dotnet run
dotnet watch

Adding package

 
dotnet add package <package name>

project file should now contain

<PackageReference Include="<package name>" Version="<package version>" />

Adding reference

 
dotnet add app/app.csproj reference lib1/lib1.csproj lib2/lib2.csproj

project file should now contain

<ItemGroup>
  <ProjectReference Include="app.csproj" />
  <ProjectReference Include="..\lib2\lib2.csproj" />
  <ProjectReference Include="..\lib1\lib1.csproj" />
</ItemGroup>

How some project file looks like

 
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
  </ItemGroup>
</Project>

Different Main methods

 
public static void Main() {}
public static int Main() {}
public static void Main(string[] args) {}
public static int Main(string[] args) {}
public static async Task Main() {}
public static async Task<int> Main() {}
public static async Task Main(string[] args) {}
public static async Task<int> Main(string[] args) {}

That's it!

.NET Core Lab 1

By Lukáš Grolig

.NET Core Lab 1

  • 320