Home > Software engineering >  Using value of int in switch pattern matching return
Using value of int in switch pattern matching return

Time:02-02

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):

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.

CodePudding user response:

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

CodePudding user response:

Made a ReSharper answer that for me eventually :)

So the syntax for it is:

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

It wasn't that obvious, hope it'll help someone

  • Related