更新时间:2023-12-04 23:42:40
是开箱 - 但它是隐式做。有一个从任何动态
表达式到任何类型的隐式转换。
It is unboxing - but it's doing it implicitly. There's an implicit conversion from any dynamic
expression to any type. The exact conversion performed will depend on the execution-time type of the value.
从C#5规范的第6.1.8节开始:
From section 6.1.8 of the C# 5 specification:
隐式动态转换从
动态
的表达式存在到任何类型T
。转换是动态绑定的(§7.2.2),这意味着将在运行时从表达式的运行时类型到
T
查找隐式转换。如果没有找到转换,则会抛出运行时异常。
An implicit dynamic conversion exists from an expression of type
dynamic
to any typeT
. The conversion is dynamically bound (§7.2.2), which means that an implicit conversion will be sought at run-time from the run-time type of the expression toT
. If no conversion is found, a run-time exception is thrown.
(这里有一点细微差别,类型动态
的表达式,而不是从动态
类型转换,转换循环,这将导致spec中其他地方的问题。)
(There's a slight nuance here in that it's a conversion from any expression of type dynamic
rather than a conversion from the dynamic
type itself. That avoids some conversion loops which would cause issues elsewhere in the spec.)