模式匹配 DateTime.DayOfWeek F#
Pattern match DateTime.DayOfWeek F#
我想从DateTime.DayOfWeek
中提取天数
match DateTime.Now.DayOfWeek with
FSI 输出类似于:
val it : DayOfWeek = Thursday {value__ = 4;}
但我不知道要匹配什么才能得到号码。我试图不匹配 ToString()-Version。有可能吗?
谢谢。
有趣的是,FSharp spec. It is not clear if an enum
value translates directly to a Simple Constant Pattern or if it is considered a Literal Pattern.
中似乎有一个缺口
尽管如此,通过使用枚举的字段名称来匹配它很简单:
match DateTime.Now.DayOfWeek with
| DayOfWeek.Thursday -> ...
我想从DateTime.DayOfWeek
中提取天数match DateTime.Now.DayOfWeek with
FSI 输出类似于:
val it : DayOfWeek = Thursday {value__ = 4;}
但我不知道要匹配什么才能得到号码。我试图不匹配 ToString()-Version。有可能吗?
谢谢。
有趣的是,FSharp spec. It is not clear if an enum
value translates directly to a Simple Constant Pattern or if it is considered a Literal Pattern.
尽管如此,通过使用枚举的字段名称来匹配它很简单:
match DateTime.Now.DayOfWeek with
| DayOfWeek.Thursday -> ...