finish lecture 2

main
borb 1 week ago
parent 4b0f5ebd72
commit c14c139d5b

@ -13,10 +13,10 @@
/* 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 xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl */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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="1" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" data-marpit-pagination-total="28">
/* @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">
<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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="2" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<h2 id="overview">Overview</h2>
<ul>
<li data-marpit-fragment="1">Variables</li>
@ -29,7 +29,7 @@
<li data-marpit-fragment="8">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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="3" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<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 +41,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="4" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<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 +55,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="5" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<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 +89,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="extra invert" data-marpit-pagination="6" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<h3 id="extra-modifiers">Extra: Modifiers</h3>
<ul>
@ -103,10 +103,10 @@ 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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="7" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="8" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" data-marpit-pagination-total="28">
</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">
<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 +123,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="9" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<h2 id="primitive-data-types">Primitive data types</h2>
<table>
<thead>
@ -181,7 +181,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="10" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<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 +193,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="extra invert" data-marpit-pagination="11" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<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 +221,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="exercise invert" data-marpit-pagination="12" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="exercise invert" data-marpit-pagination="13" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="14" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<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 +246,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="15" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<h2 id="arithmetic-operators">Arithmetic Operators</h2>
<table>
<thead>
@ -303,7 +303,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="exercise invert" data-marpit-pagination="16" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<h2 id="exercise-1-trying-out-variables">Exercise 1: Trying Out Variables</h2>
<ol>
@ -312,7 +312,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="17" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<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 +326,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="18" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<h3 id="assignment-operators">Assignment operators</h3>
<div class='columns' markdown='1'>
<div markdown='1'>
@ -380,7 +380,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="19" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<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 +392,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="20" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<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 +429,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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="extra invert" data-marpit-pagination="21" style="--paginate:true;--class:extra invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<h3 id="extra-incrementdecrement-operation-precedence">Extra: Increment/decrement operation precedence</h3>
<ul>
@ -460,61 +460,92 @@ 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-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="22" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<h2 id="strings">Strings</h2>
<p>String is a special type, which contains an array of characters. You can declare and assign strings like any other type of variables:</p>
<p>string name = &quot;Johannes Kantola&quot;;</p>
<p>You can concatenate multiple strings with the '+' operator:</p>
<p>string firstName = &quot;Johannes&quot;;</p>
<p>string lastName = &quot;Kantola&quot;;</p>
<p>string fullName = firstName + &quot; &quot; + lastName;</p>
<p>Console.WriteLine(fullName); // Outputs &quot;Johannes Kantola&quot;</p>
<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>;
</code></pre>
</li>
<li data-marpit-fragment="2">You can <em><strong>concatenate</strong></em> (i.e., combine) multiple strings with the <code>+</code> operator:<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">string</span> firstName = <span class="hljs-string">&quot;Sini&quot;</span>;
<span class="hljs-built_in">string</span> lastName = <span class="hljs-string">&quot;Aalto&quot;</span>;
<span class="hljs-built_in">string</span> fullName = firstName + <span class="hljs-string">&quot; &quot;</span> + lastName;
Console.WriteLine(fullName); <span class="hljs-comment">// Outputs &quot;Sini Aalto&quot;</span>
</code></pre>
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="23" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="23" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" data-marpit-pagination-total="28">
<h2 id="character-constants">Character Constants</h2>
<p>Character constants are preceded by a backslash '\' and can be used for formatting strings</p>
<p>'\n' represents a newline in the following example:</p>
<p>string firstName = &quot;Johannes&quot;;</p>
<p>string lastName = &quot;Kantola&quot;;</p>
<p>string fullName = firstName + &quot;\n&quot; + lastName;</p>
<p>Console.WriteLine(fullName);</p>
<p>/* This outputs</p>
<p>Johannes</p>
<p>Kantola</p>
<p>*/</p>
<p>All character constants: <a href="https://www.tutorialspoint.com/csharp/csharp_constants.htm">https://www.tutorialspoint.com/csharp/csharp_constants.htm</a></p>
</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">
<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>
<li data-marpit-fragment="2"><code>\n</code> represents a <em><strong>newline</strong></em><pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">string</span> firstName = <span class="hljs-string">&quot;Johannes&quot;</span>;
<span class="hljs-built_in">string</span> lastName = <span class="hljs-string">&quot;Kantola&quot;</span>;
<span class="hljs-built_in">string</span> fullName = firstName + <span class="hljs-string">&quot;\n&quot;</span> + lastName;
Console.WriteLine(fullName);
<span class="hljs-comment">/* This outputs
Johannes
Kantola
*/</span>
</code></pre>
</li>
<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-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="24" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" data-marpit-pagination-total="28">
<h2 id="string-interpolation">String Interpolation</h2>
<p>Concatenating multiple variables into one string with the '+' operator quickly becomes tedious</p>
<p>It's much easier to use __string interpolation __ by prefixing your target string with '$' and inserting the variables inside curly brackets '{ }':</p>
<p>string animal = &quot;Dog&quot;;</p>
<p>string sound = &quot;Woof&quot;;</p>
<p>Console.WriteLine($&quot;{animal} says {sound}!&quot;);</p>
<p>// Outputs &quot;Dog says Woof!&quot;</p>
</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">
<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>
<li data-marpit-fragment="2">It's much easier to use <em><strong>string interpolation</strong></em> by prefixing your target string with <code>$</code> and inserting the variables inside curly brackets <code>{ }</code>:<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">string</span> animal = <span class="hljs-string">&quot;Dog&quot;</span>;
<span class="hljs-built_in">string</span> sound = <span class="hljs-string">&quot;Woof&quot;</span>;
Console.WriteLine(<span class="hljs-string">$&quot;<span class="hljs-subst">{animal}</span> says <span class="hljs-subst">{sound}</span>!&quot;</span>);
<span class="hljs-comment">// Outputs &quot;Dog says Woof!&quot;</span>
</code></pre>
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="25" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="25" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" data-marpit-pagination-total="28">
<h2 id="string-formatting">String Formatting</h2>
<p>You can add <strong>format strings</strong> to change the way variables are interpolated into a string</p>
<p>Add the format string after your variable, separated by a colon (:)</p>
<p>You can find an overview of format strings and a handy list of both standard and custom strings <a href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/formatting-types">here</a></p>
<p>double pi = 3.141592653;</p>
<p>Console.WriteLine($&quot;Pi to three digits: {pi:G3}&quot;);</p>
<p>// Outputs &quot;Pi to three digits: 3.14&quot;</p>
</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">
<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>
<li data-marpit-fragment="2">Add the format string after your variable, separated by a colon (:)</li>
<li data-marpit-fragment="3">You can find an overview of format strings and a handy list of both standard and custom strings <a href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/formatting-types">here</a><pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">double</span> pi = <span class="hljs-number">3.141592653</span>;
Console.WriteLine(<span class="hljs-string">$&quot;Pi to three digits: <span class="hljs-subst">{pi:G3}</span>&quot;</span>);
<span class="hljs-comment">// Outputs &quot;Pi to three digits: 3.14&quot;</span>
</code></pre>
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="26" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="invert" data-marpit-pagination="26" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" data-marpit-pagination-total="28">
<h2 id="consolereadline">Console.ReadLine()</h2>
<p>For the next exercise, you'll need the Console.ReadLine() method. The method pauses the program, waits for an input stream from the console that pops up, and returns the value of the input:</p>
<p>string userInput = Console.ReadLine();Console.WriteLine(userInput);</p>
<p><img src="imgs/2%20Variables%20and%20Types_1.png" alt="" /></p>
</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">
<h2 id="user-input-with-consolereadline">User input with <code>Console.ReadLine()</code></h2>
<div class='columns21' markdown='1'>
<div markdown='1'>
<ul>
<li data-marpit-fragment="1">For the next exercise, you'll need the <code>Console.ReadLine()</code> method</li>
<li data-marpit-fragment="2">The method pauses the program, waits for an input stream from the console that pops up, and returns the value of the input:<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-built_in">string</span> userInput = Console.ReadLine();
Console.WriteLine(userInput);
</code></pre>
</li>
</ul>
</div>
<div markdown='1'>
<p><img src="imgs/2%20Variables%20and%20Types_1.png" alt="" style="width:200px;" /></p>
</div>
</div>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="27" data-paginate="true" data-class="exercise invert" data-heading-divider="5" data-theme="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="exercise invert" data-marpit-pagination="27" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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="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">
<h2 id="exercise-2-weekday-survey">Exercise 2: Weekday survey</h2>
<p>Create a console application which asks the user which weekday it is and assigns the answer to a string variable.</p>
<p>Print &quot;Have a nice weekday!&quot; to the console where weekday is replaced with the string the user wrote.</p>
<ol>
<li data-marpit-fragment="1">Create a console application that asks the user which weekday it is and assigns the answer to a string variable.</li>
<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="xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl" lang="en-US" class="exercise invert" data-marpit-pagination="28" style="--paginate:true;--class:exercise invert;--heading-divider:5;--theme:xgqunf1arebgoo0h9avfqhbo3l9yyeh7yl4671m79nl;" 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-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">
<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>

@ -330,87 +330,86 @@ so its value is 3
## Strings
String is a special type, which contains an array of characters. You can declare and assign strings like any other type of variables:
string name = "Johannes Kantola";
You can concatenate multiple strings with the '+' operator:
string firstName = "Johannes";
string lastName = "Kantola";
string fullName = firstName + " " + lastName;
Console.WriteLine(fullName); // Outputs "Johannes Kantola"
## Character Constants
Character constants are preceded by a backslash '\\' and can be used for formatting strings
'\\n' represents a newline in the following example:
string firstName = "Johannes";
string lastName = "Kantola";
string fullName = firstName + "\\n" + lastName;
Console.WriteLine(fullName);
/* This outputs
Johannes
Kantola
*/
All character constants: [https://www.tutorialspoint.com/csharp/csharp\_constants.htm](https://www.tutorialspoint.com/csharp/csharp_constants.htm)
## String Interpolation
Concatenating multiple variables into one string with the '+' operator quickly becomes tedious
It's much easier to use __string interpolation __ by prefixing your target string with '$' and inserting the variables inside curly brackets '{ }':
string animal = "Dog";
* `string` is a special type that contains an array of characters.
```csharp
string name = "Sini Aalto";
```
* You can ***concatenate*** (i.e., combine) multiple strings with the `+` operator:
```csharp
string firstName = "Sini";
string lastName = "Aalto";
string fullName = firstName + " " + lastName;
Console.WriteLine(fullName); // Outputs "Sini Aalto"
```
string sound = "Woof";
### Character Constants
Console.WriteLine($"{animal} says {sound}!");
* Character constants are preceded by a backslash `\` and can be used for formatting strings
* `\n` represents a ***newline***
```csharp
string firstName = "Johannes";
string lastName = "Kantola";
string fullName = firstName + "\n" + lastName;
Console.WriteLine(fullName);
// Outputs "Dog says Woof!"
/* This outputs
Johannes
## String Formatting
Kantola
*/
```
* All character constants are listed [here](https://www.tutorialspoint.com/csharp/csharp_constants.htm)
You can add __format strings__ to change the way variables are interpolated into a string
### String Interpolation
Add the format string after your variable, separated by a colon (:)
* Concatenating multiple variables into one string with the `+` operator quickly becomes tedious
* It's much easier to use *__string interpolation__* by prefixing your target string with `$` and inserting the variables inside curly brackets `{ }`:
```csharp
string animal = "Dog";
string sound = "Woof";
You can find an overview of format strings and a handy list of both standard and custom strings [here](https://learn.microsoft.com/en-us/dotnet/standard/base-types/formatting-types)
Console.WriteLine($"{animal} says {sound}!");
// Outputs "Dog says Woof!"
```
double pi = 3.141592653;
### String Formatting
Console.WriteLine($"Pi to three digits: {pi:G3}");
* You can add *__format strings__* to change the way variables are interpolated into a string
* Add the format string after your variable, separated by a colon (:)
* You can find an overview of format strings and a handy list of both standard and custom strings [here](https://learn.microsoft.com/en-us/dotnet/standard/base-types/formatting-types)
```csharp
double pi = 3.141592653;
Console.WriteLine($"Pi to three digits: {pi:G3}");
// Outputs "Pi to three digits: 3.14"
```
// Outputs "Pi to three digits: 3.14"
## User input with `Console.ReadLine()`
## Console.ReadLine()
<div class='columns21' markdown='1'>
<div markdown='1'>
For the next exercise, you'll need the Console.ReadLine() method. The method pauses the program, waits for an input stream from the console that pops up, and returns the value of the input:
* For the next exercise, you'll need the `Console.ReadLine()` method
* The method pauses the program, waits for an input stream from the console that pops up, and returns the value of the input:
```csharp
string userInput = Console.ReadLine();
Console.WriteLine(userInput);
```
string userInput = Console.ReadLine();Console.WriteLine(userInput);
</div>
<div markdown='1'>
![](imgs/2%20Variables%20and%20Types_1.png)
![w:200](imgs/2%20Variables%20and%20Types_1.png)
</div>
</div>
## Exercise 2: Weekday survey
<!--_class: "exercise invert" -->
Create a console application which asks the user which weekday it is and assigns the answer to a string variable.
Print "Have a nice weekday!" to the console where weekday is replaced with the string the user wrote.
1) Create a console application that asks the user which weekday it is and assigns the answer to a string variable.
2) Print `Have a nice <weekday>` to the console where `<weekday>` is replaced with the string the user wrote.
## Assignments (arithmetic operations)
<!--_class: "exercise invert" -->

Loading…
Cancel
Save