Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 395
Sinatr Avatar asked Dec 23 '22 20:12

Sinatr


1 Answers

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

or

(int, string) t = ((int, string))box;
like image 150
mm8 Avatar answered Feb 21 '23 22:02

mm8