1

I have a string "06:55,13:55"

I am trying to split it into variables:

var (mytime1, mytime2) = runTimes.Split(',');

but the compiler throws an error:

Severity Code Description Project File Line Suppression State Error CS8129 No suitable Deconstruct instance or extension method was found for type 'string[]', with 2 out parameters and a void return type. AA.Integrations.Aexp.Main C:\Users\username\Projects\AA\aci-integrations\AA.Integrations.Aexp.Main\SchedulerRegistry.cs 13 Active

Any idea why? Thanks.

1

2 Answers 2

6

As the compiler clearly stated, there's no Deconstruct instance or extension method was found for type string[], with 2 out parameters and a Void return type.

If you really think you need one, you can make your own:

public static class Extensions
{
    public static void Deconstruct(this string[] array, out string s1, out string s2)
    {
        s1 = array[0];
        s2 = array[1];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

C# 11 introduced List Patterns which would meet your need

if(runTimes.Split(',') is [var mytime1, var mytime2]) 
{
  Console.WriteLine($"{mytime1} ~ {mytime2}");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.