解决方案 »
- SqlCommand 的Dispose似乎不起任何作用! Why???
- 请教在代理中如何使用IDataObject
- [高分高酬] 哪位朋友帮我把 C# 的代码转成 VB.NET 的,200 分 200 元酬谢
- 批量删除问题
- 如何用C#写一个鼠标录制回放程序
- 菜鸟的问题:C#中怎么随机输入一个整型数据啊?
- c# 打印预览显示出一些文字,但是在打印时却不打印这些文字,是否可以?
- 中国软件开发者协会章程 欢迎大家提出有建设性的意见或建议!
- 如何在gridview表头添加dropdownlist以便查询?
- 在ftp://qydn.vicp.net/下载的 vs.net 2003 运行有错误,什么原因?
- C#有没有访问U盘介质的类,我想把整个U盘做成镜像文件
- waitforexit()方法不起作用!
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApplication1
{
class A
{
public int Age { get; set; }
}
class Program
{
static void Main(string[] args)
{
var exp = buildExp<A>(20);
Console.WriteLine(exp);
Console.WriteLine(exp.Compile()(new A() { Age = 17 }));
} static Expression<Func<T, bool>> buildExp<T>(int age)
{
var p = Expression.Parameter(typeof(T), "x");
var c = Expression.Constant(age, typeof(int));
var m = Expression.MakeMemberAccess(p, typeof(T).GetMember("Age")[0]);
var l = Expression.Lambda<Func<T, bool>>(Expression.GreaterThan(m, c), p);
return l;
}
}
}x => (x.Age > 20)
False
Press any key to continue . . .