8,497
社区成员
发帖
与我相关
我的任务
分享
//测试环境:vs2010;
//Framework版本:3.5
using System;
using System.Data;
namespace linqDataTable
{
class Program
{
static void Main(string[] args)
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Rows.Add(new object[] { 1 });
table.Rows.Add(new object[] { 2 });
table.Rows.Add(new object[] { 3 });
Console.WriteLine("直接输出结果:");
for (int i = 0; i < table.Rows.Count;i++ )
{
Console.WriteLine(table.Rows[i]["ID"].ToString());
}
Console.WriteLine("Linq输出结果:");
var queryInfo = from tableInfo in table.AsEnumerable()
orderby tableInfo.Field<int>("ID") descending
select tableInfo;
foreach (var item in queryInfo)
{
Console.WriteLine(item["ID"].ToString());
}
Console.ReadLine();
}
}
}
本人测试通过,如果还不行可能是编辑环境的问题吧