public class CommonReq
{
private String TransNo { get; set;}
public String SubmitData { get; set; }
private String Sign { get; set; }
public String Encoding { get; set; }
public CommonReq()
{
this.TransNo = Guid.NewGuid().ToString(); }
}
class Program
{
static void Main(string[] args)
{
//2种方式都会调用 空参数的构造函数 如果不提供空参数构造函数或不默认提供,则无法运行CreateInstance
CommonReq req = new CommonReq { SubmitData="A=1", Encoding="utf-8" };
var req2 = Activator.CreateInstance(typeof(CommonReq)) as CommonReq;
}
}