Skip to content

Commit aeeb88b

Browse files
committed
Proofread and make updates
1 parent b4da107 commit aeeb88b

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

docs/csharp/fundamentals/tutorials/records.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Use record types tutorial
33
description: Build a small app that models temperature data with records, compares record behavior, and uses with expressions for nondestructive mutation.
4-
ms.date: 04/10/2026
4+
ms.date: 04/14/2026
55
ms.topic: tutorial
66
ai-usage: ai-assisted
77
---
@@ -30,9 +30,9 @@ In this tutorial, you learn how to:
3030

3131
Create a folder for your app, run `dotnet new console`, and open the generated project.
3232

33-
Add a file named *InterimSteps.cs*, and add a positional `readonly record struct` for temperature values:
33+
Add a file named *DailyTemperature.cs*, and add a positional `readonly record struct` for temperature values:
3434

35-
:::code language="csharp" source="./snippets/records/InterimSteps.cs" ID="DailyRecord":::
35+
:::code language="csharp" source="./snippets/records/DailyTemperature.cs" ID="TemperatureRecord":::
3636

3737
Add a file named *Program.cs*, and create sample temperature data:
3838

@@ -42,19 +42,24 @@ This syntax gives you concise data modeling with immutable value semantics.
4242

4343
## Add behavior to the record struct
4444

45-
Create a file named *DailyTemperature.cs* and add a computed `Mean` property:
45+
In *DailyTemperature.cs*, you already added a computed `Mean` property to your record struct:
4646

47-
:::code language="csharp" source="./snippets/records/DailyTemperature.cs" ID="TemperatureRecord":::
47+
```csharp
48+
public double Mean => (HighTemp + LowTemp) / 2.0;
49+
```
4850

4951
A record struct works well here because each value is small and self-contained.
5052

5153
## Build record types for degree-day calculations
5254

53-
Add a hierarchy for heating and cooling degree-day calculations:
55+
> [!NOTE]
56+
> **Heating degree-days** and **cooling degree-days** measure how much the daily average temperature deviates from a base temperature (typically 65°F/18°C). Heating degree-days accumulate on cold days when the average is below the base, while cooling degree-days accumulate on warm days when the average is above the base. These calculations help estimate energy consumption for heating or cooling buildings, making them useful for utility companies, building managers, and climate analysis.
57+
58+
Create a file named *DegreeDays.cs* with a hierarchy for heating and cooling degree-day calculations:
5459

55-
:::code language="csharp" source="./snippets/records/InterimSteps.cs" ID="DegreeDaysRecords":::
60+
:::code language="csharp" source="./snippets/records/DegreeDays.cs" ID="DegreeDaysRecords":::
5661

57-
Now calculate totals from your `Main` method:
62+
Now calculate totals from your `Main` method in *Program.cs*:
5863

5964
:::code language="csharp" source="./snippets/records/Program.cs" ID="HeatingAndCooling":::
6065

docs/csharp/fundamentals/types/conversions.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Type conversions, casting, and boxing"
33
description: Learn how to convert between C# types by using implicit and explicit conversions, safe casting patterns, boxing and unboxing, and Parse and TryParse APIs.
4-
ms.date: 04/10/2026
4+
ms.date: 04/14/2026
55
ms.topic: concept-article
66
ai-usage: ai-assisted
77
---
@@ -13,7 +13,14 @@ ai-usage: ai-assisted
1313
>
1414
> **Experienced in another language?** C# conversions work like most statically typed languages: widening conversions are implicit, narrowing conversions need explicit casts, and parsing text should favor `TryParse` in user-facing code.
1515
16-
When you write C# code, you often move values from one type to another. For example, you might convert from `int` to `long`, read text and convert it to a number, or cast a base type to a derived type.
16+
When you write C# code, you often convert values from one type to another. For example, you might convert from `int` to `long`, read text and convert it to a number, or cast a base type to a derived type.
17+
18+
Understanding key terms:
19+
20+
- A *conversion* is the process of changing a value from one type to another.
21+
- A *cast* is the explicit syntax for conversion, written with parentheses like `(int)value`.
22+
- An *implicit cast* is a conversion that happens automatically when the compiler can guarantee it's safe.
23+
- An *explicit cast* is a conversion you write in code, indicating the conversion might lose information or fail.
1724

1825
Choose the conversion style based on risk:
1926

@@ -24,7 +31,7 @@ Choose the conversion style based on risk:
2431

2532
## Use implicit and explicit numeric conversions
2633

27-
Use implicit conversions when the destination type can represent the full source range. Use explicit casts when the destination type has a smaller range or less precision.
34+
An *implicit conversion* always succeeds. An *explicit conversion* might fail or lose information.
2835

2936
:::code language="csharp" source="snippets/conversions/Program.cs" ID="ImplicitAndExplicitNumeric":::
3037

@@ -34,7 +41,7 @@ For full conversion tables, see [Built-in numeric conversions](../../language-re
3441

3542
## Convert references safely
3643

37-
For reference types, you often start with a base type and need to access members from a derived type. Prefer pattern matching so the test and assignment happen together.
44+
Casts on value types typically copy the data to the destination type. Casts on reference types don't copy data; they change how you view the same object. For reference types, you often start with a base type and need to access members from a derived type. Prefer pattern matching so the test and assignment happen together.
3845

3946
:::code language="csharp" source="snippets/conversions/Program.cs" ID="ReferenceConversions":::
4047

@@ -56,7 +63,7 @@ Boxing allocates memory on the managed heap, and unboxing requires a type check.
5663

5764
## Parse text by using Parse and TryParse
5865

59-
When you convert user input or file content, start with `TryParse`. It avoids exceptions for expected invalid input and makes failure handling explicit.
66+
When you convert user input or file content, start with `TryParse`. It avoids exceptions for expected invalid input and makes failure handling explicit. All parsing APIs create a new object or value type instance from the source string; they don't modify the source.
6067

6168
:::code language="csharp" source="snippets/conversions/Program.cs" ID="ParseAndTryParse":::
6269

docs/csharp/fundamentals/types/delegates-lambdas.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Delegates, lambdas, and events"
33
description: Learn how to use Func and Action delegates, write lambda expressions, use static lambdas and discard parameters, and understand the basic event subscription model.
4-
ms.date: 04/10/2026
4+
ms.date: 04/14/2026
55
ms.topic: concept-article
66
ai-usage: ai-assisted
77
---
@@ -13,17 +13,19 @@ ai-usage: ai-assisted
1313
>
1414
> **Experienced in another language?** Think of delegates as strongly typed function variables. In modern C#, you usually write them with lambda expressions and `Func` or `Action` types.
1515
16-
Delegates let you pass behavior as data. You use delegates when code needs a callback, a rule, or a transformation that the caller supplies.
16+
*Delegates* let you pass behavior as data. You use delegates when code needs a callback, a rule, or a transformation that the caller supplies.
1717

1818
In everyday C# code, you most often use:
1919

2020
- `Func<T...>` when a delegate returns a value.
2121
- `Action<T...>` when a delegate returns `void`.
2222
- Lambda expressions to create delegate instances.
2323

24+
A *lambda expression* is an anonymous function with a compact syntax. It lets you write a function inline without naming it, using the arrow operator `=>` to separate parameters from the body.
25+
2426
## Start with Func and Action
2527

26-
`Func` and `Action` cover most delegate scenarios without creating a custom delegate type.
28+
<xref:System.Func`2?displayProperty=nameWithType> and <xref:System.Action`1?displayProperty=nameWithType> cover most delegate scenarios without creating a custom delegate type.
2729

2830
:::code language="csharp" source="snippets/delegates-lambdas/Program.cs" ID="FuncAndAction":::
2931

@@ -39,7 +41,7 @@ This pattern appears throughout LINQ and many .NET APIs.
3941

4042
## Use static lambdas when capture is unnecessary
4143

42-
A static lambda can't capture local variables. Use it when the logic depends only on parameters.
44+
A static lambda uses the `static` modifier before the parameter list, for example: `static x => x * 2` or `static (x, y) => x + y`. A static lambda can't capture local variables or instance state from the enclosing scope. *Capturing* means the lambda references variables from the enclosing scope. A *closure* is the combination of the lambda and the captured variables it holds a reference to. A non-static lambda can capture those values, while a static lambda must use only its parameters and values declared inside its body.
4345

4446
:::code language="csharp" source="snippets/delegates-lambdas/Program.cs" ID="StaticLambda":::
4547

@@ -49,6 +51,8 @@ Static lambdas make intent clear and prevent accidental captures.
4951

5052
Sometimes a delegate signature includes parameters you don't need. Use discards to signal that choice clearly.
5153

54+
Common examples include event handlers where you don't use `sender` or `EventArgs`, callbacks where you only need some of several inputs, and LINQ overloads that provide an index you don't use.
55+
5256
:::code language="csharp" source="snippets/delegates-lambdas/Program.cs" ID="DiscardParameters":::
5357

5458
Discards improve readability because they show which parameters matter.
@@ -57,6 +61,8 @@ Discards improve readability because they show which parameters matter.
5761

5862
Events expose notifications. You subscribe with a delegate, often a lambda expression.
5963

64+
Subscribing to an event is optional because publishers can raise events even when no listeners are attached. By contrast, APIs that accept a callback usually require that callback so the API can complete its work.
65+
6066
:::code language="csharp" source="snippets/delegates-lambdas/Program.cs" ID="MinimalEventIntro":::
6167

6268
This model lets publishers raise notifications without knowing subscriber implementation details.

0 commit comments

Comments
 (0)