Sinatr
Sinatr

Reputation: 21999

How to unbox tuple?

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

Upvotes: 5

Views: 1098

Answers (1)

mm8
mm8

Reputation: 169210

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

or

(int, string) t = ((int, string))box;

Upvotes: 12

Related Questions