我有一个数据表,其中一列具有0/1值。我需要使用Linq(C#)将所有的1更改为“是”(Yes),将所有的0更改为“否”(No)。
foreach(DataRow row in table.Rows)
{
string value = row.Field<string>("foo") == "0" ? "No" : "Yes";
row.SetField("foo", value);
}
使用LINQ投影:
var results = from p in myDataTable.AsEnumerable()
select new{ yesno = p.Field<int>("yesno") == 1 ? "Yes" : "No", otherField = p.Field<string>("otherField")};