4

I have boxed tuple:

(int, string) tuple = (1, "abc");
object box = tuple;

How to obtain tuple from box? What is the right syntax to cast object back to tuple?

My attempt:

var deconstruct = (int, string)box;

is obviously wrong:

Error CS1525 Invalid expression term 'int'

Error CS1525 Invalid expression term 'string'

Error CS1002 ; expected

Error CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

Community
  • 1
  • 1
Sinatr
  • 20,892
  • 15
  • 90
  • 319

1 Answers1

12
ValueTuple<int, string> t = (ValueTuple<int, string>)box;

or

(int, string) t = ((int, string))box;
mm8
  • 163,881
  • 10
  • 57
  • 88