I have a simple data type:
DataTable dt = new DataTable("myTable"); dt.Columns.Add("id", typeof (int)); dt.Columns.Add("John_a", typeof (int)); dt.Columns.Add("Paul_a", typeof (int)); dt.Columns.Add("George_b", typeof (int)); dt.Columns.Add("Ringo_b", typeof (int)); dt.Columns.Add("Yoko_a", typeof (int));
it has one line with data:
DataRow r = dt.NewRow(); r["id"] = 1; r["John_a"] = 0; r["Paul_a"] = 0; r["George_b"] =4; r["Ringo_b"] = 2; r["Yoko_a"] =10; dt.Rows.Add(r);
I need to get bool (true) response only if:
All column values ββwhose name ends with "_a" have a value of 0
So I have to get False . What for?
Becuase
John_a has 0 Paul_a has 0
but
"Yoko_a" (which also ends with "_a" ) does not have a "0", but a different number.
What I tried:
var t = dt.AsEnumerable().Select(row => dt.Columns.Cast<DataColumn>() .Where(c => c.ColumnName.ToLower().EndsWith("_a") && row.Field<int>(c.ColumnName) == 0 ) ).Any();
but returns True ....
What am I missing?
source share