Skip to content

Commit 10455c7

Browse files
authored
Merge pull request #49755 from wwlpublish/882fb6eb904537ee56fa040133256c81cb1967f9cd5ae798fd376de9b62a7fff-live
Modules/M03-implement-enum-struct-record-types
2 parents 30ce56f + 12d9169 commit 10455c7

12 files changed

+106
-10
lines changed

learn-pr/wwl-azure/implement-enum-struct-record-types/1-introduction.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: Introduction
44
metadata:
55
title: Introduction
66
description: "Introduction to the module."
7-
ms.date: 03/29/2025
7+
ms.date: 03/31/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit
11+
ms.custom:
12+
- N/A
1113
durationInMinutes: 1
1214
content: |
1315
[!include[](includes/1-introduction.md)]

learn-pr/wwl-azure/implement-enum-struct-record-types/2-use-enums-represent-named-constants-csharp.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: Use enums to represent named constants in C#
44
metadata:
55
title: Use enums to represent named constants in C#
66
description: "Learn how to use enums in C# to define named constants and improve code readability."
7-
ms.date: 03/29/2025
7+
ms.date: 03/31/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit
11+
ms.custom:
12+
- N/A
1113
durationInMinutes: 6
1214
content: |
1315
[!include[](includes/2-use-enums-represent-named-constants-csharp.md)]

learn-pr/wwl-azure/implement-enum-struct-record-types/3-create-structs-encapsulate-data-csharp.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: Create encapsulated data with structs in C#
44
metadata:
55
title: Create encapsulated data with structs in C#
66
description: "Learn how to use structs in C# to group related data into lightweight, efficient containers."
7-
ms.date: 03/29/2025
7+
ms.date: 03/31/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit
11+
ms.custom:
12+
- N/A
1113
durationInMinutes: 7
1214
content: |
1315
[!include[](includes/3-create-structs-encapsulate-data-csharp.md)]

learn-pr/wwl-azure/implement-enum-struct-record-types/4-apply-records-immutable-data-models-csharp.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: Apply records for immutable data models in C#
44
metadata:
55
title: Apply records for immutable data models in C#
66
description: "Learn how to use records in C# to create immutable data models with value-based equality."
7-
ms.date: 03/29/2025
7+
ms.date: 03/31/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit
11+
ms.custom:
12+
- N/A
1113
durationInMinutes: 8
1214
content: |
1315
[!include[](includes/4-apply-records-immutable-data-models-csharp.md)]

learn-pr/wwl-azure/implement-enum-struct-record-types/5-exercise-implement-enum-struct-record-types.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: Exercise - Implement enum, struct, and record types
44
metadata:
55
title: Exercise - Implement enum, struct, and record types
66
description: "Practice implementing enums, structs, and records in C# to reinforce your understanding of these concepts."
7-
ms.date: 03/29/2025
7+
ms.date: 03/31/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit
11+
ms.custom:
12+
- N/A
1113
durationInMinutes: 25
1214
content: |
1315
[!include[](includes/5-exercise-implement-enum-struct-record-types.md)]

learn-pr/wwl-azure/implement-enum-struct-record-types/6-knowledge-check.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: Knowledge check
44
metadata:
55
title: Knowledge check
66
description: "Check what you've learned in this module."
7-
ms.date: 03/29/2025
7+
ms.date: 03/31/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit
11+
ms.custom:
12+
- N/A
1113
durationInMinutes: 3
1214
content: |
1315
[!include[](includes/6-knowledge-check.md)]

learn-pr/wwl-azure/implement-enum-struct-record-types/7-summary.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: Summary
44
metadata:
55
title: Summary
66
description: "Summarize the key concepts covered in this module."
7-
ms.date: 03/29/2025
7+
ms.date: 03/31/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit
11+
ms.custom:
12+
- N/A
1113
durationInMinutes: 1
1214
content: |
1315
[!include[](includes/7-summary.md)]

learn-pr/wwl-azure/implement-enum-struct-record-types/includes/1-introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ Imagine you're a developer on an e-commerce platform. Order statuses like 'Pendi
1111
## Prerequisites
1212

1313
- Visual Studio Code installed with the C# Dev Kit.
14-
- Basic knowledge of the Visual Studio Code IDE.
14+
- Basic knowledge of the Visual Studio Code Integrated Development Environment (IDE).
1515
- Basic understanding of the C# programming language.
1616
- Familiar with classes, abstract classes, interfaces and inheritance.

learn-pr/wwl-azure/implement-enum-struct-record-types/includes/2-use-enums-represent-named-constants-csharp.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,37 @@ Console.WriteLine(today.IsWeekend()); // Outputs: True
123123
> [!TIP]
124124
> Use extension methods to enhance enums without modifying their definition, making them more versatile and reusable.
125125
126+
## Practical example: Using enums to manage order statuses
127+
128+
Enums are often used in applications to represent predefined values. For example, in an e-commerce application, you can use an enum to manage order statuses:
129+
130+
```csharp
131+
enum OrderStatus
132+
{
133+
Pending,
134+
Shipped,
135+
Delivered,
136+
Cancelled
137+
}
138+
139+
class Order
140+
{
141+
public int OrderId { get; set; }
142+
public OrderStatus Status { get; set; }
143+
144+
public void UpdateStatus(OrderStatus newStatus)
145+
{
146+
Status = newStatus;
147+
Console.WriteLine($"Order {OrderId} status updated to {Status}");
148+
}
149+
}
150+
151+
var order = new Order { OrderId = 123, Status = OrderStatus.Pending };
152+
order.UpdateStatus(OrderStatus.Shipped);
153+
```
154+
155+
This example demonstrates how to define an enum for order statuses, use it in a class, and update the status of an order. It helps beginners see how enums can be applied in a real-world scenario.
156+
126157
## Use object initializers with structs
127158

128159
Define a struct with properties to group related data together and make it easier to initialize and work with instances of the struct.

learn-pr/wwl-azure/implement-enum-struct-record-types/includes/3-create-structs-encapsulate-data-csharp.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public struct Rectangle
6262

6363
## Apply readonly modifier to structs for immutability
6464

65-
Immutability ensures that once a struct is created, its data can't be changed. A struct is useful when working with data that should remain constant throughout its lifetime, such as coordinates, measurements, or configuration values. By applying the `readonly` modifier to a struct, you can enforce immutability, making your code more predictable and less prone to errors caused by unintended modifications.
65+
Immutability ensures that once a struct is created, its data can't be changed. A struct is useful when working with data that should remain constant throughout its lifetime, such as coordinates, or configuration values. When you apply the `readonly` modifier to a struct, you can enforce immutability, making your code more predictable and less prone to errors caused by unintended modifications.
6666

6767
```csharp
6868
public readonly struct ImmutablePoint
@@ -108,4 +108,35 @@ var point = new Point { X = 10, Y = 20 };
108108
> [!TIP]
109109
> Object initializers make your code more concise and easier to read when working with structs that have multiple properties.
110110
111+
## Practical example: Using structs to represent points in 2D space
112+
113+
Structs are often used to represent small, immutable data structures. For example, you can use a struct to represent a point in 2D space and calculate the distance between two points:
114+
115+
```csharp
116+
public struct Point
117+
{
118+
public int X { get; }
119+
public int Y { get; }
120+
121+
public Point(int x, int y)
122+
{
123+
X = x;
124+
Y = y;
125+
}
126+
127+
public double DistanceTo(Point other)
128+
{
129+
int dx = X - other.X;
130+
int dy = Y - other.Y;
131+
return Math.Sqrt(dx * dx + dy * dy);
132+
}
133+
}
134+
135+
var point1 = new Point(3, 4);
136+
var point2 = new Point(7, 1);
137+
Console.WriteLine($"Distance between points: {point1.DistanceTo(point2)}");
138+
```
139+
140+
This example demonstrates how to define a struct for a point, calculate the distance between two points, and use the struct in a simple program.
141+
111142
Combining encapsulation, immutability, and object initializers enable you to create structs that are efficient, and predictable. These features help you manage related data in a clean and organized way.

0 commit comments

Comments
 (0)