本文整理匯總了C#中System.Dynamic.ExpandoObject.SampleMethod方法的典型用法代碼示例。如果您正苦於以下問題:C# ExpandoObject.SampleMethod方法的具體用法?C# ExpandoObject.SampleMethod怎麽用?C# ExpandoObject.SampleMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Dynamic.ExpandoObject
的用法示例。
在下文中一共展示了ExpandoObject.SampleMethod方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
static void Main(string[] args)
{
Console.WriteLine(typeof(List<dynamic>));// выдаст System.Collections.Generic.List`1[System.Object]
dynamic d = "test";
Console.WriteLine(d.GetType());// выдает System.String
object objExample = 10;
dynamic dynamicExample = 10;
Console.WriteLine(dynamicExample.GetType());
Console.WriteLine(objExample.GetType());
objExample = (int)objExample + 10; // нужен typecast
dynamicExample = dynamicExample + 10; // не нужен type cast
dynamicExample = "test";
dynamicExample = dynamicExample + 10; // не нужен type cast
Console.WriteLine(dynamicExample);// выдает "test10"
//Все вместе в перемешку - и Object, и var и dynamic - так тоже можно:
dynamic dynamicObject = new Object();
var anotherObject = dynamicObject; // What’s the type of anotherObject? The answer is: dynamic
//Remember that dynamic is in fact a static type in the C# type system, so the compiler infers this type for the anotherObject. It’s important to understand that the var keyword is just an instruction for the compiler to infer the type from the variable’s initialization expression; var is not a type.
dynamic expando = new ExpandoObject();
expando.SampleProperty = "This property was added at run time";
expando.SampleMethod = (Action)(() => Console.WriteLine(expando.SampleProperty));
// Action описан как public delegate void Action(), можно использовать так:
// Action showMethod = () => testName.DisplayToWindow();
// или так: Action showMethod = delegate() { testName.DisplayToWindow();} ;
expando.SampleMethod();
}