求高手一个问题!关于Expression>的问题

老许要老婆么 老许要老婆么 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
 public class HomeController : Controller
{
//
// GET: /Home/

public ActionResult Index()
{
int age = 12;
//第一种写法
Say(c=>c.age==12)
//第二种写法
// Say(c=>c.age==age);

return View();
}
public void Say(Expression<Func<Person,bool>> where)
{
//这里取值
string hello = where.Body.ToString();
}

public ActionResult Login()
{
return View();
}


}

public class Person
{
public string Name { set; get; }
public int age { set; get; }
public string Gender { set; get; }
}


这个是这个代码。
使用第一种写法的时候取出的值是正常的c=>c.age==12

但是第二种使用变量传进去值得时候取出来的就出错了!


其中age是从前台传过来的,这个必须得放在一个变量里,其他地方也可以使用。

/*求大神赐教!100分如果不够可以追加*/
...全文
评论 7
收藏 已收藏
分享
返回顶部
老许要老婆么
C# 111,129 成员 642,540 内容