Skip to content

Commit

Permalink
Update 1. B# vs C# vs Python.md
Browse files Browse the repository at this point in the history
Add pattern matching feature concept
  • Loading branch information
GlebSBrykin authored Nov 4, 2023
1 parent 477af62 commit 6bb415f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .content/1. B# vs C# vs Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,25 @@ sum(left, right)
</table>

Note that a strict comparison is performed in the switch operator (in the case of types, this means that the branch matching the children type with the parent type will not be executed). In switch operator the first branch that meets the condition will be executed.

More complex pattern matching sample in B#:

```C#
switch(val.GetType())
{
case typeof(int32) when ((val > 10) && (val < 100)):
{
Console.WriteLine("Case 1");
break;
}
case typeof(int32) when ((val > 100) && (val < 1000)):
{
Console.WriteLine("Case 2");
break;
}
default:
{
throw new System.Exception("Error!");
}
}
```

0 comments on commit 6bb415f

Please sign in to comment.