Step 1: Intro
This is a .NET console application written in C#. Select Run code to try it out.
Console.WriteLine("Hello World!");
Step 2: Strings
Try modifying the code so that the console says hello to your name, instead of the world (for example, Hello Ana!
). Select Run code to see if you got it right.
Console.WriteLine("Hello <name>!");
Step 3: Variables
Variables hold values that you can use elsewhere in your code.
Let's store your name in a name
variable, then read the value from that variable when creating the output message.
var name = "<name>";
Console.WriteLine("Hello " + name + "!");
Show me
var name = "<name>";
Console.WriteLine("Hello " + name + "!");
Step 4: String interpolation
String interpolation lets you piece together strings in a more concise and readable way.
If you add a $
before the opening quotes of the string, you can then include string values, like the name
variable, inside the string in curly brackets. Try it out and select Run code.
var name = "<name>";
Console.WriteLine($"Hello {name}!");
Show me
var name = "<name>";
Console.WriteLine($"Hello {name}!");
Step 5: Methods
Methods take inputs, do some work, and sometimes return a result.
ToUpper()
is a method you can invoke on a string, like the name
variable. It will return the same string, converted to uppercase.
Update the greeting to change the name of the person being greeted to uppercase and select Run code.
var name = "<name>";
Console.WriteLine($"Hello {name.ToUpper()}!");
Show me
var name = "<name>";
Console.WriteLine($"Hello {name.ToUpper()}!");
Step 6: Collections
Collections hold multiple values of the same type.
Replace the name
variable with a names
variable that has a list of names. Then use a foreach
loop to iterate over all the names and say hello to each person.
var names = new[] { "<name>", "Felipe", "Emillia" };
foreach (var name in names)
{
Console.WriteLine($"Hello {name.ToUpper()}!");
}
Show me
var names = new[] { "<name>", "Felipe", "Emillia" };
foreach (var name in names)
{
Console.WriteLine($"Hello {name.ToUpper()}!");
}