-
Notifications
You must be signed in to change notification settings - Fork 89
Use implicit match in function
CodingUnit edited this page Dec 1, 2011
·
4 revisions
- Category: Defining Operator
- Description: Use implicit pattern matching in function
- Code:
using System;
using System.Console;
variant Printer
{
| Printer0
| Printer1
| NetworkPrinter { name : string; }
}
// opens printer variant to implicitly access it's structure
using Printer;
def p = Printer0();
def p2 = NetworkPrinter("printer 123");
def matchResult(p)
{
| Printer0 => "printer 0"
| Printer1 => "printer 1"
| NetworkPrinter(n) => $"network printer $n"
}
WriteLine(matchResult(p));
WriteLine(matchResult(p2))
- Execution Result:
printer 0
network printer printer 123