You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Instructions/Labs/l2p2-lp4-m3-exercise-implement-enum-struct-record.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -424,5 +424,3 @@ Use the following steps to complete this task:
424
424
## Clean up
425
425
426
426
Now that you've finished the exercise, consider archiving your project files for review at a later time. Having your own projects available for review can be a valuable resource when you're learning to code. Additionally, building a portfolio of projects can be a great way to demonstrate your skills to potential employers.
427
-
428
-
If you no longer need the project files, you can delete the folder to free up space on your computer. However, it's recommended to keep a copy of the completed project for future reference or as part of your coding portfolio.
Copy file name to clipboardExpand all lines: Instructions/Labs/l2p2-lp4-m4-exercise-implement-generic-anonymous-types.md
+49-71Lines changed: 49 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,8 +41,13 @@ You've developed an initial version of the app that includes the following files
41
41
This exercise includes the following tasks:
42
42
43
43
1. Review the current version of your project.
44
+
1. Refactor transactions to a read-only generic API.
45
+
1. Add a Bank class that manages accounts using generics.
46
+
1. Build a reusable generic Ledger\<TEntry\> with constraints.
47
+
1. Create reports using anonymous types (LINQ projections).
48
+
1. Decide the boundary - anonymous types vs named result types.
44
49
45
-
## Review the current version of your project
50
+
## Task 1: Review the current version of your project
46
51
47
52
In this task, you download the existing version of your project and review the code.
48
53
@@ -95,11 +100,9 @@ Use the following steps to complete this section of the exercise:
95
100
96
101
## Task 2: Refactor transactions to a read-only generic API
97
102
98
-
### What to learn
99
-
100
103
Returning mutable collections like `List<T>` exposes internal state that callers can modify, breaking encapsulation. Generic read-only interfaces like `IReadOnlyList<T>` provide a safe way to expose collections without allowing mutation.
101
104
102
-
In this task, you make transactions queryable without exposing mutable internal state.
105
+
In this task, you use generic read-only interfaces to make transactions queryable without exposing mutable internal state.
103
106
104
107
Use the following steps to complete this task:
105
108
@@ -136,21 +139,13 @@ Use the following steps to complete this task:
136
139
Before:
137
140
138
141
```csharp
139
-
public void AddTransaction(decimal amount, string description)
Notice that the method now adds to the private backing list, not the public property.
@@ -162,26 +157,18 @@ Use the following steps to complete this task:
162
157
Before (iterate the backing list directly):
163
158
164
159
```csharp
165
-
public void DisplayTransactions()
160
+
foreach (Transaction transaction in Transactions)
166
161
{
167
-
Console.WriteLine("Transactions:");
168
-
foreach (Transaction transaction in _transactions)
169
-
{
170
-
Console.WriteLine(transaction);
171
-
}
162
+
Console.WriteLine(transaction);
172
163
}
173
164
```
174
165
175
166
After (iterate the read-only view):
176
167
177
168
```csharp
178
-
public void DisplayTransactions()
169
+
foreach (var transaction in Transactions)
179
170
{
180
-
Console.WriteLine("Transactions:");
181
-
foreach (var transaction in Transactions)
182
-
{
183
-
Console.WriteLine(transaction);
184
-
}
171
+
Console.WriteLine(transaction);
185
172
}
186
173
```
187
174
@@ -199,7 +186,9 @@ Use the following steps to complete this task:
199
186
200
187
1. Open the `Program.cs` file.
201
188
202
-
1. Locate the `DisplayTransactions()` method call.
189
+
1. Locate the code comment that begins with **Task 2: Step 6**.
190
+
191
+
1. Take a minute to consider the `DisplayTransactions()` method call.
203
192
204
193
You updated the `DisplayTransactions()` method to read transactions using the read-only API, so no changes are needed here. However, if you wanted to print transactions directly from `Program.cs`, you could replace the method call with something similar to the following code:
205
194
@@ -274,9 +263,9 @@ Use the following steps to complete this task:
Now that you've finished the exercise, consider archiving your project files for review at a later time. Having your own projects available for review can be a valuable resource when you're learning to code. Additionally, building a portfolio of projects can be a great way to demonstrate your skills to potential employers.
0 commit comments