finish lecture 1, move material from 1 to 1.5 and 2

main
borb 1 week ago
parent 68c9550eee
commit 29ad84902f

File diff suppressed because one or more lines are too long

@ -1,99 +1,48 @@
# Introduction to C# and .NET
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_0.png)
---
marp: true
paginate: true
math: mathjax
theme: buutti
title: 1. Introduction to C# and .NET
---
# Overview
Installing Visual Studio
A Brief History of .NET and C#
Creating Your First Application
Statements
Errors in Visual Studio 2022
Comments
# Installing Visual Studio
* Note: Visual Studio and Visual Studio Code are NOT the same thing
* Visual Studio is a full-blown IDE (integrated development environment)
* Visual Studio Code is more akin to text editors like Sublime Text, Atom etc.
* While both can be used in certain situations, the C# and ASP.NET portions of this training assume that you are using Visual Studio
* You can download the free version (Visual Studio Community) from [https://visualstudio.microsoft.com/vs/community/](https://visualstudio.microsoft.com/vs/community/)
* This downloads the setup executable for VS, which will be used to download all the modules needed (see the next slide)
# Installing Visual Studio (cont.)
* After launching the setup executable, you will be prompted to select the components to be installed along with VS. For our purposes you will need "ASP.NET and web development" portion, found in the "Workloads" tab
* Click "Install" found in the lower right corner to begin installing VS and the required components
* Note: The installation can be quite large (8 GB or more) depending on which components are already installed on your system, so we recommend using a personal hotspot if possible
* Multiple people downloading large amounts of data using the same public WIFI network will bog down the download speed for everyone
* After installing VS, you can skip the account creation portion
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_1.png)
# Introduction to C# and .NET
# .NET
<!-- headingDivider: 5 -->
<!-- class: invert -->
* .NET is Microsoft's software framework that turns your code (C#, F# or VB) into machine language
* Two types of .NET Frameworks:
* .NET Framework
* 2001
* Windows only
* Comes pre-installed with every Windows OS
* .NET Core
* 2016
* "Successor to .NET Framework"
* Open source! [https://github.com/dotnet/](https://github.com/dotnet/) _core_
* Cross-platform (Linux, Mac, Windows)
* We will be using .NET Core during this course as the old .NET Framework is pretty much legacy
## Overview
* C#
* .NET
* Common Language Infrastructure (CLI)
* Base Class Library (BCL)
* A set of libraries that every .NET implementation uses
* The libraries consist of common activities, like classes and value types, that you will use to create your programs
* No need to reinvent the wheel with every new project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
## C#
# C#
<div class='columns' markdown='1'>
<div markdown='1'>
C# was developed for .NET Framework in 2000
* 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
Microsoft wanted a Windows exclusive competitor for Java
</div>
<div markdown='1'>
Easy to understand, general purpose, object oriented
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_2.png)
![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)
# Creating a Console Application
Open Visual Studio 2022.
Select "Create a new project"
Type "console" to the search bar and select the following template:
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_3.png)
# Running a Console Application
</div>
</div>
To run your program, select "Debug" -> "Start Debugging" __or __ press F5 __or __ press the small play sign preceding your project name at the top middle
## C# Syntax example
The template project should now run and print "Hello World!" to the console. Try changing the code so that it prints something else!
# C# Syntax - Statements
<div class='columns' markdown='1'>
<div markdown='1'>
```c#
using System;
@ -110,53 +59,75 @@ namespace MyAwesomeProgram
}
```
Rows = statements
Curly brackets ' _{' _ 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
# C# Syntax - Errors in Visual Studio 2022
</div>
<div markdown='1'>
Why is this throwing an error?
* 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
Missing one closing curly bracket
</div>
</div>
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_4.png)
* Try out the [online compiler](https://www.programiz.com/csharp-programming/online-compiler/)!
Hovering on the red underline will show a hint for the error:
## .NET
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_5.png)
* .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
All errors can be displayed by pressing the red cross in the bottom:
## .NET vs .NET Framework
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_6.png)
# C# Syntax - Comments
There are two basic ways to comment in C#:
// This is a comment
* *.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
/* This is a
## Common Language Infrastructure (CLI)
multi
<div class='columns32' markdown='1'>
<div markdown='1'>
line
* 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
comment */
</div>
<div markdown='1'>
Any text inside a comment will not be executed
![](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)
Use comments to explain your code or comment out actual code for testing and debugging
</div>
</div>
## try online
## Base Class Library (BCL)
https://www.programiz.com/csharp-programming/online-compiler/
* [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
## 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)

File diff suppressed because one or more lines are too long

@ -19,7 +19,6 @@ title: 1.5. Introduction to Visual Studio
* Multiple versions released
* First version: 1997
* 2017, 2019, 2022...
* Not to be confused with [Visual Studio Code](https://code.visualstudio.com/), a separate code editor by Microsoft
## Features
@ -33,6 +32,36 @@ title: 1.5. Introduction to Visual Studio
* [Testing tools](https://learn.microsoft.com/en-us/visualstudio/test/?view=vs-2022)
* [Profiling and diagnostics tools](https://learn.microsoft.com/en-us/visualstudio/profiling/?view=vs-2022)
## Visual Studio vs Visual Studio Code (VS VS VSC)
* Visual Studio is not to be confused with [Visual Studio Code](https://code.visualstudio.com/), a separate software by Microsoft
* Visual Studio is out of the box a full-blown IDE with many built-in features
* Visual Studio Code is more akin to text editors like Sublime Text, Atom etc.
* Most features like IntelliSense or code completion have to be installed via ***plugins***
* While both can be used for many programming languages, for C# and ASP.NET Visual Studio is preferred due to its extensive debugging and build tools
## Installing Visual Studio
* Download Visual Studio Community (the free version) [here](https://visualstudio.microsoft.com/vs/community/)
<div class='columns21' markdown='1'>
<div markdown='1'>
* After launching the setup executable, you will be prompted to select the components to be installed along with VS
* For our purposes you will need ***ASP.NET and web development*** found in the ***Workloads*** tab
</div>
<div markdown='1'>
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_1.png)
</div>
</div>
* Click ***Install*** in the lower right corner to begin installing VS and the required components
* After installing VS, you can skip the account creation portion
* ***Note:*** Installation size can be quite large (8 GB+) depending on which components are already installed on your system
## Projects and solutions
* In Visual Studio, there are two key concepts, ***projects*** and ***solutions***
@ -85,6 +114,26 @@ Default view in Visual Studio consists of three panels.
</div>
</div>
## Error highlighting in Visual Studio 2022
* Visual Studio highlights errors in code automatically.
<div class='columns' markdown='1'>
<div markdown='1'>
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_4.png)
* Why is this throwing an error?
* $\Rightarrow$ Missing one closing curly bracket!
</div>
<div markdown='1'>
* Hovering on the red underline will show a hint for the error:
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_5.png)
* All errors can be displayed by pressing the red X at the bottom:
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_6.png)
## Keyboard shortcuts
* *CTRL+.*
@ -104,6 +153,21 @@ Default view in Visual Studio consists of three panels.
* Deleting files
* Adding new controllers
## Exercise 1. Creating a console application
<!--_class: "exercise invert" -->
1) Open Visual Studio 2022.
2) Select *Create a new project*
3) Type *console* to the search bar and select the following template:
![](imgs/1%20Introduction%20to%20C%23%20and%20NET_3.png)
## Exercise 2. Running a console application
<!--_class: "exercise invert" -->
1) To run your program, select *Debug > Start Debugging*, or press F5, or press the small ▶ sign next to your project name at the top
* The template project should now run and print `Hello World!` to the console.
2) Try changing the code so that it prints something else!
## Reading
* [Visual Studio Documentation: Overview](https://learn.microsoft.com/en-gb/visualstudio/get-started/visual-studio-ide?view=vs-2022)

@ -13,23 +13,24 @@
/* buutti.css */
/* @theme buutti */div#\:\$p>svg>foreignObject>section .columns{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns12{display:grid;grid-template-columns:1fr 2fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns21{display:grid;grid-template-columns:2fr 1fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns32{display:grid;grid-template-columns:3fr 2fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns23{display:grid;grid-template-columns:2fr 3fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns111{display:grid;grid-template-columns:1fr 1fr 1fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .centered{display:flex;flex-direction:column;justify-content:center;text-align:center}div#\:\$p>svg>foreignObject>section .tableborderless td,div#\:\$p>svg>foreignObject>section th{border:none!important;border-collapse:collapse}div#\:\$p>svg>foreignObject>section.extra{background-color:#5d275d;background-image:linear-gradient(to bottom,#401a40,#1d0c1d);color:white}div#\:\$p>svg>foreignObject>section.extra a{color:rgb(145,255,209)}div#\:\$p>svg>foreignObject>section.exercise{background-color:#29366f;background-image:linear-gradient(to bottom,#20636a,#173742);color:white}div#\:\$p>svg>foreignObject>section.exercise a{color:rgb(211,173,255)}
/* @theme gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr */div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]{columns:initial!important;display:block!important;padding:0!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:before,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:before{display:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]{all:initial;display:flex;flex-direction:row;height:100%;overflow:hidden;width:100%}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container][data-marpit-advanced-background-direction=vertical]{flex-direction:column}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split]>div[data-marpit-advanced-background-container]{width:var(--marpit-advanced-background-split,50%)}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split=right]>div[data-marpit-advanced-background-container]{margin-left:calc(100% - var(--marpit-advanced-background-split, 50%))}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure{all:initial;background-position:center;background-repeat:no-repeat;background-size:cover;flex:auto;margin:0}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure>figcaption{position:absolute;border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;white-space:nowrap;width:1px}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content],div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo]{background:transparent!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo],div#\:\$p>svg[data-marpit-svg]>foreignObject[data-marpit-advanced-background=pseudo]{pointer-events:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background-split]{width:100%;height:100%}</style></head><body><div class="bespoke-marp-osc"><button data-bespoke-marp-osc="prev" tabindex="-1" title="Previous slide">Previous slide</button><span data-bespoke-marp-osc="page"></span><button data-bespoke-marp-osc="next" tabindex="-1" title="Next slide">Next slide</button><button data-bespoke-marp-osc="fullscreen" tabindex="-1" title="Toggle fullscreen (f)">Toggle fullscreen</button><button data-bespoke-marp-osc="presenter" tabindex="-1" title="Open presenter view (p)">Open presenter view</button></div><div id=":$p"><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="1" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="1" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
/* @theme oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl */div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]{columns:initial!important;display:block!important;padding:0!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:before,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:before{display:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]{all:initial;display:flex;flex-direction:row;height:100%;overflow:hidden;width:100%}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container][data-marpit-advanced-background-direction=vertical]{flex-direction:column}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split]>div[data-marpit-advanced-background-container]{width:var(--marpit-advanced-background-split,50%)}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split=right]>div[data-marpit-advanced-background-container]{margin-left:calc(100% - var(--marpit-advanced-background-split, 50%))}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure{all:initial;background-position:center;background-repeat:no-repeat;background-size:cover;flex:auto;margin:0}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure>figcaption{position:absolute;border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;white-space:nowrap;width:1px}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content],div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo]{background:transparent!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo],div#\:\$p>svg[data-marpit-svg]>foreignObject[data-marpit-advanced-background=pseudo]{pointer-events:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background-split]{width:100%;height:100%}</style></head><body><div class="bespoke-marp-osc"><button data-bespoke-marp-osc="prev" tabindex="-1" title="Previous slide">Previous slide</button><span data-bespoke-marp-osc="page"></span><button data-bespoke-marp-osc="next" tabindex="-1" title="Next slide">Next slide</button><button data-bespoke-marp-osc="fullscreen" tabindex="-1" title="Toggle fullscreen (f)">Toggle fullscreen</button><button data-bespoke-marp-osc="presenter" tabindex="-1" title="Open presenter view (p)">Open presenter view</button></div><div id=":$p"><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="1" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="1" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h1 id="variables-and-types">Variables and Types</h1>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="2" data-marpit-fragments="8" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="2" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="2" data-marpit-fragments="9" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="2" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="overview">Overview</h2>
<ul>
<li data-marpit-fragment="1">Variables</li>
<li data-marpit-fragment="2">Data Types</li>
<li data-marpit-fragment="3">Arithmetic Operators</li>
<li data-marpit-fragment="4">Increment &amp; Decrement</li>
<li data-marpit-fragment="5">Assignment Operators</li>
<li data-marpit-fragment="6">Strings</li>
<li data-marpit-fragment="7">Character Constants</li>
<li data-marpit-fragment="8">String Interpolation</li>
<li data-marpit-fragment="2">Comments</li>
<li data-marpit-fragment="3">Data Types</li>
<li data-marpit-fragment="4">Arithmetic Operators</li>
<li data-marpit-fragment="5">Increment &amp; Decrement</li>
<li data-marpit-fragment="6">Assignment Operators</li>
<li data-marpit-fragment="7">Strings</li>
<li data-marpit-fragment="8">Character Constants</li>
<li data-marpit-fragment="9">String Interpolation</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="3" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="3" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="3" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="3" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="variables">Variables</h2>
<ul>
<li data-marpit-fragment="1">A variable can be thought of as a name for a certain address in computer's memory
@ -41,7 +42,7 @@
<li data-marpit-fragment="4">On more practical terms: We can assign values to named variables.</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="4" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="4" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="4" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="4" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="declaring-variables">Declaring variables</h3>
<ul>
<li data-marpit-fragment="1">Every variable declaration in C# requires the <em><strong>type</strong></em> and the <em><strong>name</strong></em> of the variable, for example:<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">int</span> x;
@ -55,7 +56,7 @@
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="5" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="5" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="5" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="5" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="printing-to-console-with-consolewriteline">Printing to console with <code>Console.WriteLine</code></h3>
<div class='columns' markdown='1'>
<div markdown='1'>
@ -89,7 +90,7 @@ Console.WriteLine(example);
</div>
</div>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="6" data-marpit-fragments="4" data-paginate="true" data-class="extra invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="extra invert" data-marpit-pagination="6" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="6" data-marpit-fragments="4" data-paginate="true" data-class="extra invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="extra invert" data-marpit-pagination="6" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="extra-modifiers">Extra: Modifiers</h3>
<ul>
@ -103,10 +104,27 @@ one = <span class="hljs-number">2</span>; <span class="hljs-comment">// raises
<li data-marpit-fragment="4">Other modifiers include <em><strong>access modifiers</strong></em> introduced in <a href="7-classes-and-objects#access-modifiers">Lecture 7</a>.</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="7" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="7" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="7" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="7" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="comments">Comments</h2>
<ul>
<li data-marpit-fragment="1">There are two basic ways to comment in C#:<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-comment">// This is a comment</span>
<span class="hljs-comment">/* This is a
multi
line
comment */</span>
</code></pre>
</li>
<li data-marpit-fragment="2">Any text inside a comment will not be executed</li>
<li data-marpit-fragment="3">Use comments to<br />
a) explain your code<br />
b) comment out actual code for testing and debugging</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="8" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="8" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="data-types">Data types</h2>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="8" data-marpit-fragments="6" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="8" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="9" data-marpit-fragments="6" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="9" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="what-is-a-data-type">What is a data type?</h3>
<ul>
<li data-marpit-fragment="1">Data type tells to a computer what type of data is stored in a variable.</li>
@ -123,7 +141,7 @@ one = <span class="hljs-number">2</span>; <span class="hljs-comment">// raises
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="9" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="9" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="10" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="10" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="primitive-data-types">Primitive data types</h2>
<table>
<thead>
@ -181,7 +199,7 @@ one = <span class="hljs-number">2</span>; <span class="hljs-comment">// raises
</table>
<p>More types listed in the <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/built-in-types">C# reference</a>!</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="10" data-marpit-fragments="1" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="10" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="11" data-marpit-fragments="1" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="11" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="data-type-examples">Data type examples</h3>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">double</span> airPressure = <span class="hljs-number">1.2</span>; <span class="hljs-comment">// Use for most decimal numbers</span>
<span class="hljs-built_in">decimal</span> accountBalance = <span class="hljs-number">1.2</span>m; <span class="hljs-comment">// Use for accuracy (e.g. financial applications)</span>
@ -193,7 +211,7 @@ one = <span class="hljs-number">2</span>; <span class="hljs-comment">// raises
<li data-marpit-fragment="1"><code>char</code> is only used for single characters, multi-character <em><strong>strings</strong></em> will be introduced in a bit.</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="11" data-marpit-fragments="2" data-paginate="true" data-class="extra invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="extra invert" data-marpit-pagination="11" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="12" data-marpit-fragments="2" data-paginate="true" data-class="extra invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="extra invert" data-marpit-pagination="12" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="extra-casting-data-types">Extra: Casting data types</h2>
<p>Data types can be <em><strong>cast</strong></em> to another either...</p>
@ -221,17 +239,17 @@ Console.WriteLine((<span class="hljs-built_in">decimal</span>)a + b);
<li data-marpit-fragment="2"><a href="https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/casting-and-type-conversions">C# Guide: Casting and type conversions</a></li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="12" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="exercise invert" data-marpit-pagination="12" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="13" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="exercise invert" data-marpit-pagination="13" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="assignments-variables">Assignments (variables)</h2>
<p><a href="https://gitea.buutti.com/education/academy-assignments/src/branch/master/C%23%20Basics/2.1.%20Variables%20&amp;%20Types">Assignments about this topic can be found here</a></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="13" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="exercise invert" data-marpit-pagination="13" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="14" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="exercise invert" data-marpit-pagination="14" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="assignments-data-types">Assignments (data types)</h2>
<p><a href="https://gitea.buutti.com/education/academy-assignments/src/branch/master/C%23%20Basics/2.2.%20Data%20Types">Assignments about this topic can be found here</a></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="14" data-marpit-fragments="7" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="14" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="15" data-marpit-fragments="7" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="15" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="arithmetic-operations">Arithmetic operations?</h2>
<ul>
<li data-marpit-fragment="1"><em><strong>Arithmetic operations</strong></em> are common mathematical operations:
@ -246,7 +264,7 @@ Console.WriteLine((<span class="hljs-built_in">decimal</span>)a + b);
<li data-marpit-fragment="7">The operations are represented by <strong><em>arithmetic operators</em></strong></li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="15" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="15" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="16" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="16" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="arithmetic-operators">Arithmetic Operators</h2>
<table>
<thead>
@ -303,7 +321,7 @@ Console.WriteLine((<span class="hljs-built_in">decimal</span>)a + b);
</tbody>
</table>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="16" data-marpit-fragments="3" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="exercise invert" data-marpit-pagination="16" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="17" data-marpit-fragments="3" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="exercise invert" data-marpit-pagination="17" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="exercise-1-trying-out-variables">Exercise 1: Trying Out Variables</h2>
<ol>
@ -312,7 +330,7 @@ Console.WriteLine((<span class="hljs-built_in">decimal</span>)a + b);
<li data-marpit-fragment="3">Print the sum, difference, fraction and product of those values to the console.</li>
</ol>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="17" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="17" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="18" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="18" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="the-assignment-operator">The assignment operator</h2>
<p>We have used the assignment operator <code>=</code> for assigning values for variables:</p>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">int</span> x;
@ -326,7 +344,7 @@ x = <span class="hljs-number">25</span>;
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="18" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="18" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="19" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="19" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="assignment-operators">Assignment operators</h3>
<div class='columns' markdown='1'>
<div markdown='1'>
@ -380,7 +398,7 @@ x = <span class="hljs-number">25</span>;
</div>
</div>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="19" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="19" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="20" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="20" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="assignment-operators-an-example">Assignment operators: An example</h3>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">int</span> uppercaseLetters = <span class="hljs-number">2</span>;
uppercaseLetters += <span class="hljs-number">4</span>; <span class="hljs-comment">// is now 6</span>
@ -392,7 +410,7 @@ Console.WriteLine(uppercaseLetters);
Console.WriteLine(specialCharacters);
</code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="20" data-marpit-fragments="5" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="20" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="21" data-marpit-fragments="5" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="21" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="increment-and-decrement-operations">Increment and decrement operations</h3>
<ul>
<li data-marpit-fragment="1">You can increment or decrement a variable value by 1 with dedicated short-hands
@ -429,7 +447,7 @@ a--; <span class="hljs-comment">// a is now 0</span>
<li data-marpit-fragment="5"><code>++</code> and <code>--</code> are called the <em><strong>increment and decrement operators</strong></em></li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="21" data-marpit-fragments="3" data-paginate="true" data-class="extra invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="extra invert" data-marpit-pagination="21" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="22" data-marpit-fragments="3" data-paginate="true" data-class="extra invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="extra invert" data-marpit-pagination="22" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="extra-incrementdecrement-operation-precedence">Extra: Increment/decrement operation precedence</h3>
<ul>
@ -460,7 +478,7 @@ so its value is 3</p>
</div>
</div>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="22" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="22" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="23" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="23" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="strings">Strings</h2>
<ul>
<li data-marpit-fragment="1"><code>string</code> is a special type that contains an array of characters.<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">string</span> name = <span class="hljs-string">&quot;Sini Aalto&quot;</span>;
@ -476,7 +494,7 @@ Console.WriteLine(fullName); <span class="hljs-comment">// Outputs &quot;Sini
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="23" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="23" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="24" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="24" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="character-constants">Character Constants</h3>
<ul>
<li data-marpit-fragment="1">Character constants are preceded by a backslash <code>\</code> and can be used for formatting strings</li>
@ -495,7 +513,7 @@ Kantola
<li data-marpit-fragment="3">All character constants are listed <a href="https://www.tutorialspoint.com/csharp/csharp_constants.htm">here</a></li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="24" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="24" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="25" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="25" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="string-interpolation">String Interpolation</h3>
<ul>
<li data-marpit-fragment="1">Concatenating multiple variables into one string with the <code>+</code> operator quickly becomes tedious</li>
@ -508,7 +526,7 @@ Console.WriteLine(<span class="hljs-string">$&quot;<span class="hljs-subst">{ani
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="25" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="25" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="26" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="26" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h3 id="string-formatting">String Formatting</h3>
<ul>
<li data-marpit-fragment="1">You can add <em><strong>format strings</strong></em> to change the way variables are interpolated into a string</li>
@ -520,7 +538,7 @@ Console.WriteLine(<span class="hljs-string">$&quot;Pi to three digits: <span cla
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="26" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="invert" data-marpit-pagination="26" style="--paginate:true;--class:invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="27" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="invert" data-marpit-pagination="27" style="--paginate:true;--class:invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="user-input-with-consolereadline">User input with <code>Console.ReadLine()</code></h2>
<div class='columns21' markdown='1'>
<div markdown='1'>
@ -537,7 +555,7 @@ Console.WriteLine(userInput);
</div>
</div>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="27" data-marpit-fragments="2" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="exercise invert" data-marpit-pagination="27" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="28" data-marpit-fragments="2" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="exercise invert" data-marpit-pagination="28" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="exercise-2-weekday-survey">Exercise 2: Weekday survey</h2>
<ol>
@ -545,7 +563,7 @@ Console.WriteLine(userInput);
<li data-marpit-fragment="2">Print <code>Have a nice &lt;weekday&gt;</code> to the console where <code>&lt;weekday&gt;</code> is replaced with the string the user wrote.</li>
</ol>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="28" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr" lang="en-US" class="exercise invert" data-marpit-pagination="28" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:gzapc67wmn4x4juhe1pf75x6urrixfh4arwl4efckrr;" data-marpit-pagination-total="28">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="29" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl" lang="en-US" class="exercise invert" data-marpit-pagination="29" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:oycqwo2imspp4a3ntzxl6ko6u92i15xqrdqfd7tfo1gl;" data-marpit-pagination-total="29">
<h2 id="assignments-arithmetic-operations">Assignments (arithmetic operations)</h2>
<p><a href="https://gitea.buutti.com/education/academy-assignments/src/branch/master/C%23%20Basics/2.3.%20Arithmetic%20Operations">Assignments about this topic can be found here</a></p>

@ -14,6 +14,7 @@ title: 2. Variables and Types
## Overview
* Variables
* Comments
* Data Types
* Arithmetic Operators
* Increment & Decrement
@ -96,6 +97,23 @@ namespace MyAwesomeProgram
* Some programmers prefer using `const` by default.
* Other modifiers include ***access modifiers*** introduced in [Lecture 7](7-classes-and-objects#access-modifiers).
## Comments
* There are two basic ways to comment in C#:
```csharp
// This is a comment
/* This is a
multi
line
comment */
```
* Any text inside a comment will not be executed
* Use comments to
a) explain your code
b) comment out actual code for testing and debugging
## Data types
### What is a data type?

Loading…
Cancel
Save