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-lp1-m3-exercise-implement-classes-csharp-apps.md
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -426,7 +426,7 @@ Use the following steps to complete this section of the exercise:
426
426
427
427
1. Notice that the Visual Studio Code environment uses red squiggly lines to indicate errors in your code.
428
428
429
-
There are two issues that you need to address:
429
+
There are two primary issues that you need to address:
430
430
431
431
- The methods in a static class must be static, so you need to update the method signatures to include the `static` keyword.
432
432
- The properties and fields defined by the `BankAccount` class are not directly accessible in the `Transactions` class. You need to update the method signatures to accept a `BankAccount` parameter and use the `BankAccount` instance to access properties within the static methods.
@@ -446,9 +446,9 @@ Use the following steps to complete this section of the exercise:
446
446
447
447
```
448
448
449
-
The `Deposit` method came from the `BankAccount` class, where it could access the `Balance` property directly. However, the `Balance` property is no longer available in the `Transactions` class. To update the `Deposit` method, you need to update the method signature to accept a `BankAccount` parameter, and then use the `BankAccount` instance to access the `Balance` property.
449
+
The `Deposit` method came from the `BankAccount` class, where it could access the `Balance` property directly. However, the `Balance` property is no longer available in the `Transactions` class. To update the `Deposit` method, you need to update the method signature to accept a `BankAccount` parameter, and then use the `BankAccount` instance to access the `Balance` property. Also, you need to add `static` to the method signature to make it a static method.
450
450
451
-
1. To add a `BankAccount` parameter to the signature and then reference the account object within the method, update the `Deposit` method to match the following code snippet:
451
+
1. To add a `static` modifier and `BankAccount` parameter to the signature, and then reference the account object within the method, update the `Deposit` method to match the following code snippet:
452
452
453
453
```csharp
454
454
@@ -463,9 +463,11 @@ Use the following steps to complete this section of the exercise:
463
463
464
464
```
465
465
466
-
Notice that the `Deposit` method now accepts a `BankAccount` parameter named `account`, and that it uses the `account` object to access the `Balance` property. All good so far.
466
+
Notice that the `Deposit` method now accepts a `BankAccount` parameter named `account`, and that it uses the `account` object to access the `Balance` property.
467
467
468
-
However, when the code attempts to update the `account.Balance` property using the `amount` parameter, it finds that the `Balance` property isn't accessible. This is because the setter is private. To update the `Balance` property in the static method, you need to change access control of the setter to `internal`. This will allow the `Transactions` class to modify the `Balance` property while keeping the property encapsulated within the `BankAccount` class.
468
+
However, when the code attempts to update the `account.Balance` property using the `amount` parameter, it finds that the set accessor is inaccessible. You can hover the mouse pointer over the `Balance` property to see the error message.
469
+
470
+
The `Balance` property is inaccessible in `Transactions` because the setter is defined as `private` in `BankAccount`. To update the `Balance` property in your static methods, you need to change access control of the setter to `internal` in the `BankAccount` class. This update will allow the `Transactions` class to modify the `Balance` property while keeping the property encapsulated within the `BankAccount` class.
469
471
470
472
1. Open the BankAccount.cs file.
471
473
@@ -479,7 +481,7 @@ Use the following steps to complete this section of the exercise:
479
481
480
482
1. Switch back to the Transactions.cs file.
481
483
482
-
1. Notice that the `Deposit` method now has access to the `Balance` property of the `BankAccount` instance.
484
+
1. Notice that the `Deposit` method is now able to set the `account.Balance` property.
483
485
484
486
1. Repeat the process used to update `Deposit` to correct the issues in the remaining `Transactions` class methods.
485
487
@@ -635,7 +637,7 @@ Use the following steps to complete this section of the exercise:
635
637
636
638
1. Run the app to ensure that your static class updates didn't introduce any bugs.
637
639
638
-
By moving the transactional methods to a static class, you can organize your code more effectively and improve the readability and maintainability of your code. The BankAccount class should still work as expected, and you should see the same output in the terminal window.
640
+
By moving the transactional methods to a static class, your code is more efficiently organized and the maintainability of your code is improved. The BankAccount class should still work as expected, and you should see the same output in the terminal window.
639
641
640
642
Your app should produce output that's similar to the following example:
641
643
@@ -849,7 +851,7 @@ Use the following steps to complete this section of the exercise:
0 commit comments