|
28 | 28 | Console.WriteLine();
|
29 | 29 | FirstEnumExample.ExampleProgram.Main();
|
30 | 30 | Console.WriteLine();
|
31 |
| -SwitchEnumValueExample(bankRecords); |
| 31 | +EnumSwitchExample.ExampleProgram.Main(); |
32 | 32 | Console.WriteLine();
|
33 | 33 | ExampleProgram.Main();
|
34 | 34 | Console.WriteLine();
|
@@ -61,42 +61,3 @@ static void IsTextValueExample(string bankRecords)
|
61 | 61 | // </IsOnTextValue>
|
62 | 62 | }
|
63 | 63 |
|
64 |
| -static void SwitchEnumValueExample(string bankRecords) |
65 |
| -{ |
66 |
| - // <SwitchEnumValue> |
67 |
| - double currentBalance = 0.0; |
68 |
| - |
69 |
| - foreach (var transaction in TransactionRecords(bankRecords)) |
70 |
| - { |
71 |
| - currentBalance += transaction switch |
72 |
| - { |
73 |
| - (TransactionType.Deposit, var amount) => amount, |
74 |
| - (TransactionType.Withdrawal, var amount) => -amount, |
75 |
| - _ => 0.0 |
76 |
| - }; |
77 |
| - Console.WriteLine($"{transaction.type} => Parsed Amount: {transaction.amount}, New Balance: {currentBalance}"); |
78 |
| - } |
79 |
| - |
80 |
| - static IEnumerable<(TransactionType type, double amount)> TransactionRecords(string inputText) |
81 |
| - { |
82 |
| - var reader = new StringReader(inputText); |
83 |
| - string? line; |
84 |
| - while ((line = reader.ReadLine()) != null) |
85 |
| - { |
86 |
| - string[] parts = line.Split(','); |
87 |
| - |
88 |
| - string? transactionType = parts[0]?.Trim(); |
89 |
| - if (double.TryParse(parts[1].Trim(), out double amount)) |
90 |
| - { |
91 |
| - // Update the balance based on transaction type |
92 |
| - if (transactionType?.ToUpper() is "DEPOSIT") |
93 |
| - yield return (TransactionType.Deposit, amount); |
94 |
| - else if (transactionType?.ToUpper() is "WITHDRAWAL") |
95 |
| - yield return (TransactionType.Withdrawal, amount); |
96 |
| - } |
97 |
| - yield return (default, 0.0); |
98 |
| - } |
99 |
| - } |
100 |
| - // </SwitchEnumValue> |
101 |
| -} |
102 |
| - |
0 commit comments