Skip to content

Commit 3f9d154

Browse files
committed
First pass edit.
1 parent 3aec531 commit 3f9d154

File tree

3 files changed

+92
-118
lines changed

3 files changed

+92
-118
lines changed

docs/csharp/tour-of-csharp/tutorials/hello-world.md

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
---
2-
title: Hello World - Introductory interactive tutorial
3-
description: In this tutorial, you use your browser to learn C# interactively. You write C# code and see the results of compiling and running your code directly in the browser.
4-
ms.date: 03/05/2025
2+
title: Hello World - Introductory tutorial
3+
description: In this tutorial, you create your first C# apps. You write C# code and learn basic structure and types in C#.
4+
ms.date: 12/02/2025
55
---
6-
# Introduction to C# - interactive tutorial
6+
# Introduction to C# - tutorial
77

8-
This tutorial teaches you C# interactively, using your browser to write C# and see the results of compiling and running your code. It contains a series of lessons that begin with a "Hello World" program. These lessons teach you the fundamentals of the C# language.
9-
10-
> [!TIP]
11-
>
12-
> When a code snippet block includes the "Run" button, that button opens the interactive window, or replaces the existing code in the interactive window. When the snippet doesn't include a "Run" button, you can copy the code and add it to the current interactive window.
8+
This tutorial teaches you C#. You write your first C# and see the results of compiling and running your code. It contains a series of lessons that begin with a "Hello World" program. These lessons teach you the fundamentals of the C# language.
139

1410
## Run your first program
1511

16-
Run the following code in the interactive window.
12+
TODO: `dotnet new` or create a file.
1713

18-
:::code language="csharp" interactive="try-dotnet-method" source="./snippets/HelloWorld/Program.cs" id="HelloWorld":::
14+
Type the following code in your new `cs` file:
1915

20-
Congratulations! You ran your first C# program. It's a simple program that prints the message "Hello World!" It used the <xref:System.Console.WriteLine%2A?displayProperty=nameWithType> method to print that message. `Console` is a type that represents the console window. `WriteLine` is a method of the `Console` type that prints a line of text to that text console.
16+
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="HelloWorld":::
17+
18+
TODO: To run the program, type `dotnet run` (or) `dotnet file.cs` at the command prompt. Congratulations! You ran your first C# program. It's a simple program that prints the message "Hello World!" It used the <xref:System.Console.WriteLine%2A?displayProperty=nameWithType> method to print that message. `Console` is a type that represents the console window. `WriteLine` is a method of the `Console` type that prints a line of text to that text console.
2119

2220
Let's move on and explore more. The rest of this lesson explores working with the `string` type, which represents text in C#. Like the `Console` type, the `string` type has methods. The `string` methods work with text.
2321

@@ -27,18 +25,18 @@ Your first program printed the `string` "Hello World!" on the screen.
2725

2826
> [!TIP]
2927
>
30-
> As you explore C# (or any programming language), you make mistakes when you write code. The **compiler** finds those errors and report them to you. When the output contains error messages, look closely at the example code, and the code in the interactive window to see what to fix. That exercise helps you learn the structure of C# code.
28+
> As you explore C# (or any programming language), you make mistakes when you write code. The **compiler** finds those errors and report them to you. When the output contains error messages, look closely at the example code, and the code in your `.cs` file to see what to fix. That exercise helps you learn the structure of C# code.
3129
3230
Your first program is limited to printing one message. You can write more useful programs by using *variables*. A *variable* is a symbol you can use to run the same code with different values. Let's try it! Start with the following code:
3331

34-
:::code language="csharp" interactive="try-dotnet-method" source="./snippets/HelloWorld/Program.cs" id="Variables":::
32+
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="Variables":::
3533

3634
The first line declares a variable, `aFriend`, and assigns it a value, "Bill". The second line prints the name.
3735

38-
You can assign different values to any variable you declare. You can change the name to one of your friends. Add these two lines in the preceding interactive window following the code you already added. Make sure you keep the declaration of the `aFriend` variable and its initial assignment.
36+
You can assign different values to any variable you declare. You can change the name to one of your friends. Add these two lines following the code you already added. Make sure you keep the declaration of the `aFriend` variable and its initial assignment.
3937

4038
> [!IMPORTANT]
41-
> Don't delete the declaration of `aFriend`. Add the following code at the end of the preceding interactive window:
39+
> Don't delete the declaration of `aFriend`. Add the following code at the end of the preceding code:
4240
4341
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="Assignment":::
4442

@@ -48,33 +46,33 @@ You might notice that the word "Hello" was missing in the last two messages. Let
4846

4947
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="ConcatMessage":::
5048

51-
Select **Run** again to see the results.
49+
TODO: Run the app again using `dotnet run` (or) `dotnet file.cs` to see the results.
5250

5351
You've been using `+` to build strings from **variables** and **constant** strings. There's a better way. You can place a variable between `{` and `}` characters to tell C# to replace that text with the value of the variable.
5452

5553
This process is called [String interpolation](../../language-reference/tokens/interpolated.md).
5654

5755
If you add a `$` before the opening quote of the string, you can then include variables, like `aFriend`, inside the string between curly braces. Give it a try:
5856

59-
Select **Run** again to see the results. Instead of "Hello {aFriend}", the message should be "Hello Maira".
60-
6157
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="Interpolation":::
6258

59+
TODO: Run the app again using `dotnet run` (or) `dotnet file.cs` to see the results. Instead of "Hello {aFriend}", the message should be "Hello Maira".
60+
6361
## Work with strings
6462

6563
Your last edit was our first look at what you can do with strings. Let's explore more.
6664

67-
You're not limited to a single variable between the curly braces. Try the following code:
65+
You're not limited to a single variable between the curly braces. Try the following code at the bottom of your app:
6866

69-
:::code language="csharp" interactive="try-dotnet-method" source="./snippets/HelloWorld/Program.cs" id="WorkWithStrings":::
67+
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="WorkWithStrings":::
7068

71-
Strings are more than a collection of letters. You can find the length of a string using `Length`. `Length` is a **property** of a string and it returns the number of characters in that string. Add the following code at the bottom of the interactive window:
69+
Strings are more than a collection of letters. You can find the length of a string using `Length`. `Length` is a **property** of a string and it returns the number of characters in that string. Add the following code at the bottom of your app:
7270

7371
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="Properties":::
7472

7573
> [!TIP]
7674
>
77-
> Now is a good time to explore on your own. You learned that `Console.WriteLine()` writes text to the screen. You learned how to declare variables and concatenate strings together. Experiment in the interactive window. The window has a feature called *IntelliSense* that makes suggestions for what you can do. Type a `.` after the `d` in `firstFriend`. You see a list of suggestions for properties and methods you can use.
75+
> Now is a good time to explore on your own. You learned that `Console.WriteLine()` writes text to the screen. You learned how to declare variables and concatenate strings together. Experiment in your code. Your editor has a feature called *IntelliSense* that makes suggestions for what you can do. Type a `.` after the `d` in `firstFriend`. You see a list of suggestions for properties and methods you can use.
7876
7977
You've been using a *method*, <xref:System.Console.WriteLine%2A?displayProperty=nameWithType>, to print messages. A *method* is a block of code that implements some action. It has a name, so you can access it.
8078

@@ -83,7 +81,7 @@ You've been using a *method*, <xref:System.Console.WriteLine%2A?displayProperty=
8381
Suppose your strings have leading or trailing spaces that you don't want to display. You want to **trim** the spaces from the strings.
8482
The <xref:System.String.Trim%2A> method and related methods <xref:System.String.TrimStart%2A> and <xref:System.String.TrimEnd%2A> do that work. You can just use those methods to remove leading and trailing spaces. Try the following code:
8583

86-
:::code language="csharp" interactive="try-dotnet-method" source="./snippets/HelloWorld/Program.cs" id="Trim":::
84+
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="Trim":::
8785

8886
The square brackets `[` and `]` help visualize what the `Trim`, `TrimStart,` and, `TrimEnd` methods do. The brackets show where whitespace starts and ends.
8987

@@ -93,7 +91,7 @@ This sample reinforces a couple of important concepts for working with strings.
9391

9492
There are other methods available to work with a string. For example, you probably used a search and replace command in an editor or word processor before. The <xref:System.String.Replace%2A> method does something similar in a string. It searches for a substring and replaces it with different text. The <xref:System.String.Replace%2A> method takes two **parameters**. These parameters are the strings between the parentheses. The first string is the text to search for. The second string is the text to replace it with. Try it for yourself. Add this code. Type it in to see the hints as you start typing `.Re` after the `sayHello` variable:
9593

96-
:::code language="csharp" interactive="try-dotnet-method" source="./snippets/HelloWorld/Program.cs" id="Replace":::
94+
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="Replace":::
9795

9896
Two other useful methods make a string ALL CAPS or all lower case. Try the following code. Type it in to see how **IntelliSense** provides hints as you start to type `To`:
9997

@@ -103,7 +101,7 @@ Two other useful methods make a string ALL CAPS or all lower case. Try the follo
103101

104102
The other part of a *search and replace* operation is to find text in a string. You can use the <xref:System.String.Contains%2A> method for searching. It tells you if a string contains a substring inside it. Try the following code to explore <xref:System.String.Contains%2A>:
105103

106-
:::code language="csharp" interactive="try-dotnet-method" source="./snippets/HelloWorld/Program.cs" id="SearchStrings":::
104+
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="SearchStrings":::
107105

108106
The <xref:System.String.Contains%2A> method returns a *boolean* value which tells you if the string you were searching for was found. A *boolean* stores either a `true` or a `false` value. When displayed as text output, they're capitalized: `True` and `False`, respectively. You learn more about *boolean* values in a later lesson.
109107

@@ -122,11 +120,11 @@ Did you come up with something like the following (expand to see the answer):
122120
<!-- markdownlint-disable MD033 -->
123121
<details>
124122

125-
:::code language="csharp" interactive="try-dotnet-method" source="./snippets/HelloWorld/Program.cs" id="Challenge":::
123+
:::code language="csharp" source="./snippets/HelloWorld/Program.cs" id="Challenge":::
126124
</details>
127125
<!-- markdownlint-enable MD033 -->
128126

129-
You completed the "Hello C#" introduction to C# tutorial. You can select the **Numbers in C#** tutorial to start the next interactive tutorial, or you can visit the [.NET site](https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/intro) to download the .NET SDK, create a project on your machine, and keep coding. The "Next steps" section brings you back to these tutorials.
127+
You completed the "Hello C#" introduction to C# tutorial. You can select the **Numbers in C#** tutorial to start the next tutorial, or you can visit the [.NET site](https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/intro) to download the .NET SDK, create a project on your machine, and keep coding. The "Next steps" section brings you back to these tutorials.
130128

131129
For further reading on the `string` type:
132130

docs/csharp/tour-of-csharp/tutorials/snippets/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

docs/csharp/tour-of-csharp/tutorials/snippets/HelloWorld/Program.cs

Lines changed: 65 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,69 @@
1-
PageOne();
2-
PageTwo();
3-
PageThree();
4-
PageFour();
5-
PageFive();
6-
PageSix();
7-
Challenge();
8-
9-
void PageOne()
10-
{
11-
// <HelloWorld>
12-
Console.WriteLine("Hello, World!");
13-
// </HelloWorld>
14-
}
15-
16-
void PageTwo()
17-
{
18-
// <Variables>
19-
string aFriend = "Bill";
20-
Console.WriteLine(aFriend);
21-
// </Variables>
22-
23-
// <Assignment>
24-
aFriend = "Maira";
25-
Console.WriteLine(aFriend);
26-
// </Assignment>
27-
28-
// <ConcatMessage>
29-
Console.WriteLine("Hello " + aFriend);
30-
// </ConcatMessage>
31-
32-
// <Interpolation>
33-
Console.WriteLine($"Hello {aFriend}");
34-
// </Interpolation>
35-
}
36-
37-
void PageThree()
38-
{
39-
// <WorkWithStrings>
40-
string firstFriend = "Maria";
41-
string secondFriend = "Sage";
42-
Console.WriteLine($"My friends are {firstFriend} and {secondFriend}");
43-
// </WorkWithStrings>
44-
45-
// <Properties>
46-
Console.WriteLine($"The name {firstFriend} has {firstFriend.Length} letters.");
47-
Console.WriteLine($"The name {secondFriend} has {secondFriend.Length} letters.");
48-
// </Properties>
49-
}
50-
51-
void PageFour()
52-
{
53-
// <Trim>
54-
string greeting = " Hello World! ";
55-
Console.WriteLine($"[{greeting}]");
1+
// <HelloWorld>
2+
Console.WriteLine("Hello, World!");
3+
// </HelloWorld>
4+
5+
// <Variables>
6+
string aFriend = "Bill";
7+
Console.WriteLine(aFriend);
8+
// </Variables>
9+
10+
// <Assignment>
11+
aFriend = "Maira";
12+
Console.WriteLine(aFriend);
13+
// </Assignment>
14+
15+
// <ConcatMessage>
16+
Console.WriteLine("Hello " + aFriend);
17+
// </ConcatMessage>
18+
19+
// <Interpolation>
20+
Console.WriteLine($"Hello {aFriend}");
21+
// </Interpolation>
22+
23+
// <WorkWithStrings>
24+
string firstFriend = "Maria";
25+
string secondFriend = "Sage";
26+
Console.WriteLine($"My friends are {firstFriend} and {secondFriend}");
27+
// </WorkWithStrings>
28+
29+
// <Properties>
30+
Console.WriteLine($"The name {firstFriend} has {firstFriend.Length} letters.");
31+
Console.WriteLine($"The name {secondFriend} has {secondFriend.Length} letters.");
32+
// </Properties>
33+
34+
// <Trim>
35+
string greeting = " Hello World! ";
36+
Console.WriteLine($"[{greeting}]");
37+
38+
string trimmedGreeting = greeting.TrimStart();
39+
Console.WriteLine($"[{trimmedGreeting}]");
40+
41+
trimmedGreeting = greeting.TrimEnd();
42+
Console.WriteLine($"[{trimmedGreeting}]");
43+
44+
trimmedGreeting = greeting.Trim();
45+
Console.WriteLine($"[{trimmedGreeting}]");
46+
// </Trim>
47+
48+
// <Replace>
49+
string sayHello = "Hello World!";
50+
Console.WriteLine(sayHello);
51+
sayHello = sayHello.Replace("Hello", "Greetings");
52+
Console.WriteLine(sayHello);
53+
// </Replace>
54+
55+
// <UpperLower>
56+
Console.WriteLine(sayHello.ToUpper());
57+
Console.WriteLine(sayHello.ToLower());
58+
// </UpperLower>
59+
60+
// <SearchStrings>
61+
string songLyrics = "You say goodbye, and I say hello";
62+
Console.WriteLine(songLyrics.Contains("goodbye"));
63+
Console.WriteLine(songLyrics.Contains("greetings"));
64+
// </SearchStrings>
5665

57-
string trimmedGreeting = greeting.TrimStart();
58-
Console.WriteLine($"[{trimmedGreeting}]");
59-
60-
trimmedGreeting = greeting.TrimEnd();
61-
Console.WriteLine($"[{trimmedGreeting}]");
62-
63-
trimmedGreeting = greeting.Trim();
64-
Console.WriteLine($"[{trimmedGreeting}]");
65-
// </Trim>
66-
}
67-
68-
void PageFive()
69-
{
70-
// <Replace>
71-
string sayHello = "Hello World!";
72-
Console.WriteLine(sayHello);
73-
sayHello = sayHello.Replace("Hello", "Greetings");
74-
Console.WriteLine(sayHello);
75-
// </Replace>
76-
77-
// <UpperLower>
78-
Console.WriteLine(sayHello.ToUpper());
79-
Console.WriteLine(sayHello.ToLower());
80-
// </UpperLower>
81-
}
82-
83-
void PageSix()
84-
{
85-
// <SearchStrings>
86-
string songLyrics = "You say goodbye, and I say hello";
87-
Console.WriteLine(songLyrics.Contains("goodbye"));
88-
Console.WriteLine(songLyrics.Contains("greetings"));
89-
// </SearchStrings>
90-
}
66+
Challenge();
9167

9268
void Challenge()
9369
{

0 commit comments

Comments
 (0)