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.

monstro
  • 6,254
  • 10
  • 65
  • 111
  • Possible duplicate of [Does C# 7 have array/enumerable destructuring?](https://stackoverflow.com/questions/47815660/does-c-sharp-7-have-array-enumerable-destructuring) – Felix K. Dec 04 '18 at 18:31

1 Answers1

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];
    }
}
Paulo Morgado
  • 14,111
  • 3
  • 31
  • 59