Home

C# 7.3 support?

Does linqpad have c# 7.3 support?

c# 7.3 added equality support for tuples (== and !=) and while the following code works in Visual Studio 15.7 Preview, its causes a compilation error in linqpad 5.31

`(1,1) == (1,2)`

`CS0019 Operator '==' cannot be applied to operands of type '(int, int)' and '(int, int)'`

Comments

  • This sample statement does not appear to work although LinqPad states 7.3 support:

    var value = 2;
    
    var result=  value switch
    {
    
        1 => "Case 1",  
        2 => "Case 2",  
        3 => "Case 3",  
        4 => "Case 4",  
    };
    

    results in:

    CS1002 ; expected

    CS1003 Syntax error, '(' expected

    CS1525 Invalid expression term '{'

    CS1026 ) expected

    I am sorry to be out of it, but these really simple examples should work, yes? Or do I need to set an option somewhere?

    What I really want to do is this:

    Replace all these if statements :

            **    if (e.Argument.StartsWith(@"DISCARD:INSPECTION"))
                {
                    DiscardInspection();
                }
    
                if (e.Argument == @"ERROR")
                {
                    Response.Redirect("~/Error.aspx");
                }
    
                if (e.Argument == @"EXPIRATION")
                {
                    Log?.Debug("EditFormCS redirects to Expiration");
                    Response.Redirect("~/Expiration.aspx");
                }**
    

    with :

    var action = e.Argument switch
    {
    e.ArgumentStartsWith(@"DISCARD:INSPECTION")) => DiscardInspection(),
    e.Argument == @"ERROR" => Response.Redirect("~/Error.aspx"),
    e.Argument == @"EXPIRATION" =>  {
                        Log?.Debug("EditFormCS redirects to Expiration");
                        Response.Redirect("~/Expiration.aspx");
                    },
    ...
    ...
    ...
    ..
    

    }

    and then invoke the action...

    Hopeless?

    Thank you.

  • Works ok with LinqPad 6 beta, so I'm guessing you are using LinqPad 5.

  • Switch expressions were introduced in C# 8, which requires .NET Core (and hence LINQPad 6).

Sign In or Register to comment.