/// <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, "這是個錯誤!"); } }
新聞熱點
疑難解答