ASP.NET SharpEightInfo类(2)

  /// <summary>
        /// C#8新语法
        /// </summary>
        /// <param name="week"></param>
        /// <returns></returns>
        public static string WeekToString(WeekInfo week) => week switch
        {
            WeekInfo.Monday => "周一",
            WeekInfo.Tuesday => "周二",
            WeekInfo.Wednesday => "周三",
            WeekInfo.Thursday => "周四",
            WeekInfo.Friday => "周五",
            WeekInfo.Saturday => "周六",
            WeekInfo.Sunday => "周七",
            _ => throw new NotImplementedException("枚举不存在"),
        };

        /// <summary>
        ///switch 经典switch
        /// </summary>
        /// <param name="week"></param>
        /// <returns></returns>
        public static string WeekToStringSwitch(WeekInfo week)
        {
            switch (week)
            {
                case WeekInfo.Monday:
                    return "周一";

                case WeekInfo.Tuesday:
                    return "周二";

                case WeekInfo.Wednesday:
                    return "周三";

                case WeekInfo.Thursday:
                    return "周四";

                case WeekInfo.Friday:
                    return "周五";

                case WeekInfo.Saturday:
                    return "周六";

                case WeekInfo.Sunday:
                    return "周七";

                default:
                    throw new NotImplementedException("枚举不存在");

            }
        }

        /// <summary>
        ///switch 属性模式
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        public static double PropertyPatternShow(PropertyPattern pattern) => pattern
            switch
        {
            { ProductName: "朝夕架构班" } => pattern.Price * 0.5,
            { Price: 234 } => pattern.Price * 0.5, 
            _ => throw new NotImplementedException(),
        };

        /// <summary>
        /// switch 元组模式
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public static string RockPaperScissors(string first, string second)
    => (first, second) switch
    {
        ("444", "教育1") => $"{first}-{second}",
        ("444", "教育2") => $"{first}-{second}",
        ("444", "教育3") => $"{first}-{second}",
        (_, _) => "不匹配"
    };

       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_74456535

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值