1.词汇
- dynamic type 动态类型
- implicitly 隐式的
2.例句
-
Dynamic type is that the C# compiler allows you to use dynamically. If an expression is of type dynamic, you can call methods on it, access properties, pass it around as a method argument, and so on—and most of the normal binding process happens at execution time instead of compile time. You can implicitly convert a value from dynamic to any other type.
C#编译器允许动态使用该类型,如果一个表达式为动态类型,你可以调用它的方法,访问它的属性,把其作为参数等等,大多数的绑定发生在执行时而不是编译时,你也可以隐式的把动态类型转换为任意其它类型。
-
This behavior can also be useful even within pure C# code, with no interop involved, but it’s fun to see it working with other languages.
即使在纯粹的C#代码中,虽然不需要与com对象交互,但可能与与其他语言交互,这样的行为也是十分有意义的。
3.代码
- 下面的代码展示的是,嵌入的ironpython脚本,使用dynamic操作
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.ExecuteFile("FindProducts.py");
dynamic products = scope.GetVariable("products");
foreach (dynamic product in products)
{
Console.WriteLine("{0}: {1}", product.ProductName, product.Price);
}