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