Skip to content

Pattern Matching - A Tour of C# | Microsoft Learn #52946

@mattalto

Description

@mattalto

Type of issue

Missing information

Description

Hello,

I am working my way through some of the resources provided through Microsoft Learn, and noticed a small error in the following code under Enum Matching section of the Pattern Matching - A Tour of C# module:

currentBalance = 0.0;

foreach (var transaction in TransactionRecords(bankRecords))
{
    if (transaction.type == TransactionType.Deposit)
        currentBalance += transaction.amount;
    else if (transaction.type == TransactionType.Withdrawal)
        currentBalance -= transaction.amount;
    Console.WriteLine($"{transaction.type} => Parsed Amount: {transaction.amount}, New Balance: {currentBalance}");
}

currentBalance should be preceded with the double value type. Otherwise, the code won't compile.

I hope this is useful, and thank you for providing these resources!

Best,
Matt

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/tutorials/pattern-matching

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/tour-of-csharp/tutorials/pattern-matching.md

Document Version Independent Id

d68419a1-0819-2456-ef95-bfa0a05ec55a

Platform Id

dafef79e-b177-be72-40ff-77db2c38557f

Article author

@BillWagner

Metadata

  • ID: cc9b5079-735d-15fc-f5f5-eca009731538
  • PlatformId: dafef79e-b177-be72-40ff-77db2c38557f
  • Service: dotnet-csharp
  • Sub-service: get-started

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions