SrNo Roll Name Result
1 1 XYZ 0
99 45 ABC 0
10 9 RTY 0
150 120 POQ 1
190 180 MNZ 1
试试这个:
var dt = new DataTable();
dt.Columns.Add(new DataColumn("SrNo", typeof (int)));
dt.Columns.Add(new DataColumn("Roll", typeof (int)));
dt.Columns.Add(new DataColumn("Name", typeof (string)));
dt.Rows.Add(1, 1, "XYZ");
dt.Rows.Add(99, 45, "ABC");
dt.Rows.Add(150, 120, "POQ");
dt.Rows.Add(10, 9, "RTY");
dt.Rows.Add(190, 180, "MNZ");
var result = from r in dt.AsEnumerable()
orderby (r.Field<int>("Roll") >= 100) ascending
select new
{
SrNo = r.Field<int>("SrNo"),
Roll = r.Field<int>("Roll"),
Name = r.Field<string>("Name"),
Result = Convert.ToInt32(Math.Floor(r.Field<int>("Roll")/100.0))
};
Console.WriteLine(
"{0}\t{1}\t{2}\t{3}",
"SrNo",
"Roll",
"Name",
"Result");
foreach (var row in result)
{
Console.WriteLine(
"{0}\t{1}\t{2}\t{3}",
row.SrNo,
row.Roll,
row.Name,
row.Result);
}
任何机会,你可以让你在找什么更清晰? – soandos 2011-05-31 06:12:59
其实这是我无法解决的问题的一部分,所以我现在已经发布完整的问题 – usr021986 2011-05-31 06:13:11
这似乎是一个家庭作业问题。 – tofutim 2011-05-31 06:19:31