我正在尝试向 ExpandoObject 添加一个动态方法,该方法会将属性(动态添加)返回给它,但是它总是给我错误。
我在这里做错了什么吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
namespace DynamicDemo
{
class ExpandoFun
{
public static void Main()
{
Console.WriteLine("Fun with Expandos...");
dynamic student = new ExpandoObject();
student.FirstName = "John";
student.LastName = "Doe";
student.Introduction=new Action(()=>
Console.WriteLine("Hello my name is {0} {1}",this.FirstName,this.LastName);
);
Console.WriteLine(student.FirstName);
student.Introduction();
}
}
}
编译器标记以下错误:错误 1
关键字“this”在静态属性、静态方法或静态字段初始值设定项中无效
D:\rnd\GettingStarted\DynamicDemo\ExpandoFun.cs 20 63 DynamicDemo