1.詞匯
- dynamic type 動(dòng)態(tài)類型
- 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#編譯器允許動(dòng)態(tài)使用該類型,如果一個(gè)表達(dá)式為動(dòng)態(tài)類型,你可以調(diào)用它的方法,訪問它的屬性,把其作為參數(shù)等等,大多數(shù)的綁定發(fā)生在執(zhí)行時(shí)而不是編譯時(shí),你也可以隱式的把動(dòng)態(tài)類型轉(zhuǎn)換為任意其它類型。
-
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);
}