/// <summary> /// 如何写出一个无返回值,可接受LINQ参数的方法。 /// </summary> public class product { public string name { get; set; } public int id { get; set; } public void Require(Expression<Func<product, string>> expression, string tip) { Func<product, string> func = expression.Compile(); if (string.IsNullOrEmpty(func(this))) { throw new Exception(tip); } } public product() { this.Require(t => t.name, "这是个错误!"); } }