我有盒装元组:
(int, string) tuple = (1, "abc");
object box = tuple;
如何从box
中获取元组?将 object
转换回元组的正确语法是什么?
我的尝试:
var deconstruct = (int, string)box;
显然是错误的:
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
最佳答案
ValueTuple<int, string> t = (ValueTuple<int, string>)box;
或
(int, string) t = ((int, string))box;
关于c# - 如何拆箱元组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58506346/