diff --git a/2-variables-and-types-slides.html b/2-variables-and-types-slides.html index cbf9f82..993ef4c 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 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%}
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"
+string
is a special type that contains an array of characters.string name = "Sini Aalto";
+
++
operator:string firstName = "Sini";
+string lastName = "Aalto";
+
+string fullName = firstName + " " + lastName;
+
+Console.WriteLine(fullName); // Outputs "Sini Aalto"
+
+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
+\
and can be used for formatting strings\n
represents a newlinestring firstName = "Johannes";
+string lastName = "Kantola";
+string fullName = firstName + "\n" + lastName;
+Console.WriteLine(fullName);
+
+/* This outputs
+Johannes
+
+Kantola
+*/
+
+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 sound = "Woof";
-Console.WriteLine($"{animal} says {sound}!");
-// Outputs "Dog says Woof!"
++
operator quickly becomes tedious$
and inserting the variables inside curly brackets { }
:string animal = "Dog";
+string sound = "Woof";
+
+Console.WriteLine($"{animal} says {sound}!");
+// Outputs "Dog says Woof!"
+
+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
-double pi = 3.141592653;
-Console.WriteLine($"Pi to three digits: {pi:G3}");
-// Outputs "Pi to three digits: 3.14"
+double pi = 3.141592653;
+Console.WriteLine($"Pi to three digits: {pi:G3}");
+// Outputs "Pi to three digits: 3.14"
+
+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:
-string userInput = Console.ReadLine();Console.WriteLine(userInput);
-Console.ReadLine()
Console.ReadLine()
methodstring userInput = Console.ReadLine();
+Console.WriteLine(userInput);
+
+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.
+Have a nice <weekday>
to the console where <weekday>
is replaced with the string the user wrote.Assignments about this topic can be found here
diff --git a/2-variables-and-types.md b/2-variables-and-types.md index 913729c..613b53d 100644 --- a/2-variables-and-types.md +++ b/2-variables-and-types.md @@ -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() +