在下面的真实世界的例子中我做了一个匹配:
type Style = Nice | Cool | Ugly
type Color = Blue | Yellow | Orange | Grey | Cyan
type ClothingProperties = Style * Color
type Clothes =
| Jeans of ClothingProperties
| Pullover of ClothingProperties
| Shirt of ClothingProperties
type Person =
| Person of string * Clothes
let team = [Person("Jan", Jeans (Cool, Blue)); Person("Pete", Shirt (Nice, Cyan)); Person("Harry", Pullover (Ugly, Grey))]
let matchPerson person=
match person with
| Person(name, Jeans(Ugly,_) ) -> printfn "%s wears …Run Code Online (Sandbox Code Playgroud) f# functional-programming pattern-matching discriminated-union
我有一个C#/ WPF应用程序,根据它是否已从Windows任务栏上的固定链接启动,我希望给出不同的行为。