C#英語筆記Day 33

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);
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容