C#英语笔记Day 33

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);
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容