简体   繁体   English

在开关模式匹配返回中使用 int 的值

[英]Using value of int in switch pattern matching return

Seems to be something very simple I'm missing, but can't find any example of how to handle such case.似乎是我所缺少的非常简单的东西,但找不到任何如何处理这种情况的例子。 I need to construct a switch statement like this (pseudocode):我需要构造一个这样的 switch 语句(伪代码):

a+b switch
{
   var sum: >0 => sum
};

I have a strong feeling that it should be possible for value types without using when, but I can't find syntax for this.我有一种强烈的感觉,值类型应该可以不使用 when,但我找不到它的语法。

a + b switch
{
   > 0 => returnValue;
   _ => catchAll;
}

Made a ReSharper answer that for me eventually:)最终为我做了一个 ReSharper 答案:)

So the syntax for it is:所以它的语法是:

a+b switch
{
   var sum and >0 => sum
};

It wasn't that obvious, hope it'll help someone这不是那么明显,希望它能帮助别人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM