Skip to content

Commit d413d8a

Browse files
committed
finish samples
1 parent 35337be commit d413d8a

File tree

3 files changed

+1
-42
lines changed

3 files changed

+1
-42
lines changed

docs/csharp/tour-of-csharp/tutorials/pattern-matching.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ All the examples in this tutorial use the following data. Select "Run" to start
3131

3232
:::code language="csharp" interactive="try-dotnet-method" source="./snippets/PatternMatching/Program.cs" id="SwitchEnumValue":::
3333

34-
3534
The following code declares and uses a `record` type to represent a `Point`, and then uses that `Point` structure in the `Main` method:
3635

3736
:::code language="csharp" interactive="try-dotnet" source="./snippets/PatternMatching/Program.cs" id="FinalProgram":::

docs/csharp/tour-of-csharp/tutorials/snippets/PatternMatching/FinalExampleProgram.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public enum TransactionType
6969
Withdrawal
7070
}
7171

72-
7372
public record Deposit(double Amount, string description);
7473
public record Withdrawal(double Amount, string description);
7574

docs/csharp/tour-of-csharp/tutorials/snippets/PatternMatching/Program.cs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
Console.WriteLine();
2929
FirstEnumExample.ExampleProgram.Main();
3030
Console.WriteLine();
31-
SwitchEnumValueExample(bankRecords);
31+
EnumSwitchExample.ExampleProgram.Main();
3232
Console.WriteLine();
3333
ExampleProgram.Main();
3434
Console.WriteLine();
@@ -61,42 +61,3 @@ static void IsTextValueExample(string bankRecords)
6161
// </IsOnTextValue>
6262
}
6363

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

Comments
 (0)