Implementing pattern matching in C#

后端 未结 5 1754
耶瑟儿~
耶瑟儿~ 2021-02-04 03:54

In Scala, you can use pattern matching to produce a result depending on the type of the input. For instance:

val title = content match {
    case blogPost: BlogP         


        
5条回答
  •  遇见更好的自我
    2021-02-04 04:17

    Using Functional C# (from @Alireza)

    var title = content.Match()
       .With(blogPost => blogPost.Blog.Title + ": " + blogPost.Title)
       .With(blog => blog.Title)
       .Result();
    

提交回复
热议问题