You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
csharp-basics/1-introduction-to-csharp-an...

134 lines
4.0 KiB
Markdown

---
marp: true
paginate: true
math: mathjax
theme: buutti
title: 1. Introduction to C# and .NET
---
# Introduction to C# and .NET
<!-- headingDivider: 5 -->
<!-- class: invert -->
## Overview
* C#
* .NET
* Common Language Infrastructure (CLI)
* Base Class Library (BCL)
## C#
<div class='columns' markdown='1'>
<div markdown='1'>
* The C# (pronounced *c sharp*) programming language was introduced by Microsoft in 2000, alongside the .NET framework
* Unlike C and C++, C# runs on a virtual machine like Java
* Easy to understand, general purpose, high-level, object oriented
* Resembles Java, which was very popular in the 90s
* Newest version is 13.0 from 2024
</div>
<div markdown='1'>
![w:600](imgs/1%20Introduction%20to%20C%23%20and%20NET_2.png)
Source: [http://pypl.github.io/PYPL.html](http://pypl.github.io/PYPL.html)
</div>
</div>
## C# Syntax example
<div class='columns' markdown='1'>
<div markdown='1'>
```c#
using System;
namespace MyAwesomeProgram
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
```
</div>
<div markdown='1'>
* Everything is inside a `class`
* Rows = statements
* Curly braces `{` and `}` mark the start and the end of different ***bodies*** of statements
* Semicolon `;` at the end of some statements
* When to use semicolon? Don't worry: Visual Studio will tell you
</div>
</div>
* Try out the [online compiler](https://www.programiz.com/csharp-programming/online-compiler/)!
## .NET
* .NET (pronounced *dot net*) is Microsoft's software framework for building and running web services
* [.NET fundamentals](https://learn.microsoft.com/en-us/dotnet/fundamentals/), [Introduction to .NET](https://learn.microsoft.com/en-us/dotnet/core/introduction)
* Fully supports C#, F# and Visual Basic
* Implements Common Language Infrastructure, so it can compile managed code (languages above) into machine code
* Provides [automatic memory management](https://learn.microsoft.com/en-us/dotnet/standard/automatic-memory-management) via a garbage collector (GC)
* Type-safe and memory-safe thanks to GC and strict compilers
## .NET vs .NET Framework
* *.NET Framework*
* Launched in 2001
* Closed-source
* Windows-only
* Current version 4.8.1 launched in 2022
* *.NET* (originally *.NET core*)
* Launched in 2016, Successor to .NET Framework
* [Open source]([https://github.com/dotnet/](https://github.com/dotnet/))
* Cross-platform (Linux, Mac, Windows)
* Current version 9.0 launched in 2024
* We will be using .NET Core as the .NET Framework is considered legacy
## Common Language Infrastructure (CLI)
<div class='columns32' markdown='1'>
<div markdown='1'>
* Common Language Infrastructure (CLI) is a standardized specification that decribes how different high-level langauges (like C#) can be run on different platforms without having to be rewritten
* both versions of .NET are ***implementations*** of the CLI
* Another implementation is the free and open-source [Mono](https://www.mono-project.com/) project
* Used by the Unity game engine and the MonoGame framework
</div>
<div markdown='1'>
![](https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Overview_of_the_Common_Language_Infrastructure_2015.svg/800px-Overview_of_the_Common_Language_Infrastructure_2015.svg.png)
</div>
</div>
## Base Class Library (BCL)
* [Base Class Library](https://learn.microsoft.com/en-us/dotnet/standard/class-library-overview) (BCL) is a set of libraries that every .NET implementation uses, mostly under the `System` namespace
* Consists of common tools like classes and value types that you will need to create your programs
* No need to reinvent the wheel with every new project
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
```
## Assignments
<!--_class: "exercise invert" -->
[Assignments about this topic can be found here](https://gitea.buutti.com/education/academy-assignments/src/branch/master/C%23%20Basics/1.%20C%23%20Basics%20Assignments)