diff --git a/0-introduction-to-csharp-and-dotnet-slides.html b/0-introduction-to-csharp-and-dotnet-slides.html index 38814e4..d57974e 100644 --- a/0-introduction-to-csharp-and-dotnet-slides.html +++ b/0-introduction-to-csharp-and-dotnet-slides.html @@ -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 wsuiybveupon7ttrwf1y86brx8jn1excr6rrqrkgej */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%}
using System; +using System; namespace MyAwesomeProgram { @@ -75,7 +75,7 @@ Try out the online compiler! - + .NET .NET (pronounced dot net) is Microsoft's software framework for building and running web services @@ -89,7 +89,7 @@ Type-safe and memory-safe thanks to GC and strict compilers - + .NET vs .NET Framework .NET Framework @@ -111,7 +111,7 @@ We will be using .NET Core as the .NET Framework is considered legacy - + Common Language Infrastructure (CLI) @@ -130,7 +130,7 @@ - + Base Class Library (BCL) Base Class Library (BCL) is a set of libraries that every .NET implementation uses, mostly under the System namespace @@ -143,7 +143,7 @@ - + Assignments Assignments about this topic can be found here diff --git a/0-introduction-to-csharp-and-dotnet.md b/0-introduction-to-csharp-and-dotnet.md index a7e3cf7..4d328bf 100644 --- a/0-introduction-to-csharp-and-dotnet.md +++ b/0-introduction-to-csharp-and-dotnet.md @@ -44,7 +44,7 @@ Source: [http://pypl.github.io/PYPL.html](http://pypl.github.io/PYPL.html) -```c# +```csharp using System; namespace MyAwesomeProgram diff --git a/2-variables-and-types-slides.html b/2-variables-and-types-slides.html index 8bd971c..977a464 100644 --- a/2-variables-and-types-slides.html +++ b/2-variables-and-types-slides.html @@ -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 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%}Previous slideNext slideToggle fullscreenOpen presenter view +/* @theme 8yiv4e0xl4wj3nyluwl608ntiyon4jevegr5ghaz83p */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%}Previous slideNext slideToggle fullscreenOpen presenter view Variables and Types - + Overview Variables @@ -30,7 +30,7 @@ String Interpolation - + Variables A variable can be thought of as a name for a certain address in computer's memory @@ -42,7 +42,7 @@ On more practical terms: We can assign values to named variables. - + Declaring variables Every variable declaration in C# requires the type and the name of the variable, for example:int x; @@ -56,7 +56,7 @@ - + Printing to console with Console.WriteLine @@ -90,12 +90,12 @@ Console.WriteLine(example); - + Extra: Modifiers A common modifier to add in front of a variable is const, short for constant -If we know that a value of a variable is never going to change during the execution of the script, we can set it to const:const int one = 1; +If we know that a value of a variable is never going to change during the execution of the script, we can set it to const:const int one = 1; one = 2; // raises an error @@ -104,7 +104,7 @@ one = 2; // raises Other modifiers include access modifiers introduced in Lecture 7. - + Comments There are two basic ways to comment in C#:// This is a comment @@ -121,10 +121,10 @@ a) explain your code b) comment out actual code for testing and debugging - + Data types - + What is a data type? Data type tells to a computer what type of data is stored in a variable. @@ -141,7 +141,7 @@ b) comment out actual code for testing and debugging - + Primitive data types @@ -199,7 +199,7 @@ b) comment out actual code for testing and debugging More types listed in the C# reference! - + Data type examples double airPressure = 1.2; // Use for most decimal numbers decimal accountBalance = 1.2m; // Use for accuracy (e.g. financial applications) @@ -211,7 +211,7 @@ b) comment out actual code for testing and debugging char is only used for single characters, multi-character strings will be introduced in a bit. - + Extra: Casting data types Data types can be cast to another either... @@ -239,17 +239,17 @@ Console.WriteLine((decimal)a + b); C# Guide: Casting and type conversions - + Assignments (variables) Assignments about this topic can be found here - + Assignments (data types) Assignments about this topic can be found here - + Arithmetic operations? Arithmetic operations are common mathematical operations: @@ -264,7 +264,7 @@ Console.WriteLine((decimal)a + b); The operations are represented by arithmetic operators - + Arithmetic Operators @@ -321,7 +321,7 @@ Console.WriteLine((decimal)a + b); - + Exercise 1: Trying Out Variables @@ -330,7 +330,7 @@ Console.WriteLine((decimal)a + b); Print the sum, difference, fraction and product of those values to the console. - + The assignment operator We have used the assignment operator = for assigning values for variables: int x; @@ -344,7 +344,7 @@ x = 25; - + Assignment operators @@ -398,7 +398,7 @@ x = 25; - + Assignment operators: An example int uppercaseLetters = 2; uppercaseLetters += 4; // is now 6 @@ -410,7 +410,7 @@ Console.WriteLine(uppercaseLetters); Console.WriteLine(specialCharacters); - + Increment and decrement operations You can increment or decrement a variable value by 1 with dedicated short-hands @@ -447,7 +447,7 @@ a--; // a is now 0 ++ and -- are called the increment and decrement operators - + Extra: Increment/decrement operation precedence @@ -478,7 +478,7 @@ so its value is 3 - + Strings string is a special type that contains an array of characters.string name = "Sini Aalto"; @@ -494,7 +494,7 @@ Console.WriteLine(fullName); // Outputs "Sini - + Character Constants Character constants are preceded by a backslash \ and can be used for formatting strings @@ -513,7 +513,7 @@ Kantola All character constants are listed here - + String Interpolation Concatenating multiple variables into one string with the + operator quickly becomes tedious @@ -526,7 +526,7 @@ Console.WriteLine($"{ani - + String Formatting You can add format strings to change the way variables are interpolated into a string @@ -538,7 +538,7 @@ Console.WriteLine($"Pi to three digits: - + User input with Console.ReadLine() @@ -555,7 +555,7 @@ Console.WriteLine(userInput); - + Exercise 2: Weekday survey @@ -563,7 +563,7 @@ Console.WriteLine(userInput); Print Have a nice <weekday> to the console where <weekday> is replaced with the string the user wrote. - + Assignments (arithmetic operations) Assignments about this topic can be found here diff --git a/2-variables-and-types.md b/2-variables-and-types.md index f599aed..ff5c805 100644 --- a/2-variables-and-types.md +++ b/2-variables-and-types.md @@ -89,7 +89,7 @@ namespace MyAwesomeProgram * A common modifier to add in front of a variable is `const`, short for ***constant*** * If we know that a value of a variable is never going to change during the execution of the script, we can set it to `const`: - ```c# + ```csharp const int one = 1; one = 2; // raises an error
using System; namespace MyAwesomeProgram { @@ -75,7 +75,7 @@ Try out the online compiler! - + .NET .NET (pronounced dot net) is Microsoft's software framework for building and running web services @@ -89,7 +89,7 @@ Type-safe and memory-safe thanks to GC and strict compilers - + .NET vs .NET Framework .NET Framework @@ -111,7 +111,7 @@ We will be using .NET Core as the .NET Framework is considered legacy - + Common Language Infrastructure (CLI) @@ -130,7 +130,7 @@ - + Base Class Library (BCL) Base Class Library (BCL) is a set of libraries that every .NET implementation uses, mostly under the System namespace @@ -143,7 +143,7 @@ - + Assignments Assignments about this topic can be found here diff --git a/0-introduction-to-csharp-and-dotnet.md b/0-introduction-to-csharp-and-dotnet.md index a7e3cf7..4d328bf 100644 --- a/0-introduction-to-csharp-and-dotnet.md +++ b/0-introduction-to-csharp-and-dotnet.md @@ -44,7 +44,7 @@ Source: [http://pypl.github.io/PYPL.html](http://pypl.github.io/PYPL.html) -```c# +```csharp using System; namespace MyAwesomeProgram diff --git a/2-variables-and-types-slides.html b/2-variables-and-types-slides.html index 8bd971c..977a464 100644 --- a/2-variables-and-types-slides.html +++ b/2-variables-and-types-slides.html @@ -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 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%}Previous slideNext slideToggle fullscreenOpen presenter view +/* @theme 8yiv4e0xl4wj3nyluwl608ntiyon4jevegr5ghaz83p */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%}Previous slideNext slideToggle fullscreenOpen presenter view Variables and Types - + Overview Variables @@ -30,7 +30,7 @@ String Interpolation - + Variables A variable can be thought of as a name for a certain address in computer's memory @@ -42,7 +42,7 @@ On more practical terms: We can assign values to named variables. - + Declaring variables Every variable declaration in C# requires the type and the name of the variable, for example:int x; @@ -56,7 +56,7 @@ - + Printing to console with Console.WriteLine @@ -90,12 +90,12 @@ Console.WriteLine(example); - + Extra: Modifiers A common modifier to add in front of a variable is const, short for constant -If we know that a value of a variable is never going to change during the execution of the script, we can set it to const:const int one = 1; +If we know that a value of a variable is never going to change during the execution of the script, we can set it to const:const int one = 1; one = 2; // raises an error @@ -104,7 +104,7 @@ one = 2; // raises Other modifiers include access modifiers introduced in Lecture 7. - + Comments There are two basic ways to comment in C#:// This is a comment @@ -121,10 +121,10 @@ a) explain your code b) comment out actual code for testing and debugging - + Data types - + What is a data type? Data type tells to a computer what type of data is stored in a variable. @@ -141,7 +141,7 @@ b) comment out actual code for testing and debugging - + Primitive data types @@ -199,7 +199,7 @@ b) comment out actual code for testing and debugging More types listed in the C# reference! - + Data type examples double airPressure = 1.2; // Use for most decimal numbers decimal accountBalance = 1.2m; // Use for accuracy (e.g. financial applications) @@ -211,7 +211,7 @@ b) comment out actual code for testing and debugging char is only used for single characters, multi-character strings will be introduced in a bit. - + Extra: Casting data types Data types can be cast to another either... @@ -239,17 +239,17 @@ Console.WriteLine((decimal)a + b); C# Guide: Casting and type conversions - + Assignments (variables) Assignments about this topic can be found here - + Assignments (data types) Assignments about this topic can be found here - + Arithmetic operations? Arithmetic operations are common mathematical operations: @@ -264,7 +264,7 @@ Console.WriteLine((decimal)a + b); The operations are represented by arithmetic operators - + Arithmetic Operators @@ -321,7 +321,7 @@ Console.WriteLine((decimal)a + b); - + Exercise 1: Trying Out Variables @@ -330,7 +330,7 @@ Console.WriteLine((decimal)a + b); Print the sum, difference, fraction and product of those values to the console. - + The assignment operator We have used the assignment operator = for assigning values for variables: int x; @@ -344,7 +344,7 @@ x = 25; - + Assignment operators @@ -398,7 +398,7 @@ x = 25; - + Assignment operators: An example int uppercaseLetters = 2; uppercaseLetters += 4; // is now 6 @@ -410,7 +410,7 @@ Console.WriteLine(uppercaseLetters); Console.WriteLine(specialCharacters); - + Increment and decrement operations You can increment or decrement a variable value by 1 with dedicated short-hands @@ -447,7 +447,7 @@ a--; // a is now 0 ++ and -- are called the increment and decrement operators - + Extra: Increment/decrement operation precedence @@ -478,7 +478,7 @@ so its value is 3 - + Strings string is a special type that contains an array of characters.string name = "Sini Aalto"; @@ -494,7 +494,7 @@ Console.WriteLine(fullName); // Outputs "Sini - + Character Constants Character constants are preceded by a backslash \ and can be used for formatting strings @@ -513,7 +513,7 @@ Kantola All character constants are listed here - + String Interpolation Concatenating multiple variables into one string with the + operator quickly becomes tedious @@ -526,7 +526,7 @@ Console.WriteLine($"{ani - + String Formatting You can add format strings to change the way variables are interpolated into a string @@ -538,7 +538,7 @@ Console.WriteLine($"Pi to three digits: - + User input with Console.ReadLine() @@ -555,7 +555,7 @@ Console.WriteLine(userInput); - + Exercise 2: Weekday survey @@ -563,7 +563,7 @@ Console.WriteLine(userInput); Print Have a nice <weekday> to the console where <weekday> is replaced with the string the user wrote. - + Assignments (arithmetic operations) Assignments about this topic can be found here diff --git a/2-variables-and-types.md b/2-variables-and-types.md index f599aed..ff5c805 100644 --- a/2-variables-and-types.md +++ b/2-variables-and-types.md @@ -89,7 +89,7 @@ namespace MyAwesomeProgram * A common modifier to add in front of a variable is `const`, short for ***constant*** * If we know that a value of a variable is never going to change during the execution of the script, we can set it to `const`: - ```c# + ```csharp const int one = 1; one = 2; // raises an error
System
Assignments about this topic can be found here
int x; @@ -56,7 +56,7 @@
Console.WriteLine
const
const int one = 1; +If we know that a value of a variable is never going to change during the execution of the script, we can set it to const:const int one = 1; one = 2; // raises an error @@ -104,7 +104,7 @@ one = 2; // raises Other modifiers include access modifiers introduced in Lecture 7.
const int one = 1; one = 2; // raises an error
// This is a comment @@ -121,10 +121,10 @@ a) explain your code b) comment out actual code for testing and debugging
More types listed in the C# reference!
double airPressure = 1.2; // Use for most decimal numbers decimal accountBalance = 1.2m; // Use for accuracy (e.g. financial applications) @@ -211,7 +211,7 @@ b) comment out actual code for testing and debugging char is only used for single characters, multi-character strings will be introduced in a bit.
char
Data types can be cast to another either...
We have used the assignment operator = for assigning values for variables:
=
int x; @@ -344,7 +344,7 @@ x = 25;
int uppercaseLetters = 2; uppercaseLetters += 4; // is now 6 @@ -410,7 +410,7 @@ Console.WriteLine(uppercaseLetters); Console.WriteLine(specialCharacters);
++
--
string
string name = "Sini Aalto"; @@ -494,7 +494,7 @@ Console.WriteLine(fullName); // Outputs "Sini
\
+
Console.ReadLine()
Have a nice <weekday>
<weekday>