You can achieve that using 2 methods:
1)
DataTable.Compute(String, String) Method (System.Data) | Microsoft Docs[
^]
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("Variable", typeof(string)),
new DataColumn("Contents", typeof(int))
});
dt.Rows.Add(new object[]{"a", 0});
dt.Rows.Add(new object[]{"b", 3});
dt.Rows.Add(new object[]{"c", 6});
var sumObject = dt.Compute("Sum(Contents)", "Variable IN ('a', 'b', 'c')");
2)
Enumerable.Sum Method (System.Linq) | Microsoft Docs[
^]
string[] tofind = {"a", "b", "c"};
var result = dt.AsEnumerable()
.Where(x => tofind.Any(y=> (x.Field<string>("Variable").Equals(y))))
.Sum(x=>x.Field<int>("Contents"));
You might be interested in reading this excellent article:
A Calculation Engine for .NET[
^]