解决方案 »
- 当传递具有已删除行的 DataRow 集合时,更新要求有效的 DeleteCommand
- 从数据库里读数据,怎么只要其中一段
- Winform 子线程影响到主线程运行的奇怪问题
- C#基础问题???
- 99分,求installshield使用教程
- 一个关于极限证明的问题。(c#新手)
- C#2.0实现ICollection和ICollection<T>的问题,高手帮忙~分不够可以再加~!~在线等~
- 请教用c#写个程序把excel中的数据导入到sql server,用什么方法比较快?
- 事件来源: .NET Runtime 2.0 Error Reporting,事件 ID: 5000
- 括号里面的参数什么含义啊....
- 请教一下这个时间日期的格式要怎么输出?
- Repeater绑定linq数据源 失败提示“未将对象引用设置到对象的实例。”
{
foreach (var p in listT)
{ }
}
那个。。俺用的2005 貌似var不出来?
{
foreach (T p in listT)
{
如果这里写
int i = p.Age;如果
GetModelList<int>就会有问题了。
}
}因此你的情况不适合使用泛型。
例如public class MyGenericClass<T> where T : IComparable, new()
{
// The following line is not possible without new() constraint:
T item = new T();
}这样,就可以在函数里使用item.CompareTo(...) 也可以new了。参考
where (generic type constraint) (C# Reference)
http://msdn.microsoft.com/en-us/library/bb384067.aspx
static void GetModelList<T>(List<T> listT,Action<T> act)
{
foreach (var p in listT)
{
act(p);
}
}GetModelList<TEST>(persons,p=>p.xxx=1);
{
foreach (PropertyInfo pinfo in typeof(T).GetProperties())
{
Console.Write(pinfo.Name+":"+pinfo.GetValue(p, null));
Console.WriteLine();
} } 获取值可以,但是你要返回对象就难了,所以你这个方法不靠谱