C# Calculation using Data Table Compute

Thomas Jacob 0 Reputation points

I have been using C# Datatable.Compute function to do calculations.

Example:Dot net version 5.0

Given that , Datatable dt = new Datatable();

var a=4000

var b =24

var str = dt.Compute((a/b).ToString(), string.Empty);

The gen0 garbage collector invocation for this single operation is high.

Could you suggest an alternate function to this?


Thomas JacobUntitled


An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,470 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 113.7K Reputation points

    Probably you meant dt.Compute( $"{a} / {b}", string.Empty ).

    0 comments No comments

  2. Bruce (SqlWork.com) 59,036 Reputation points

    its a rather heavy operation. the expression must be parsed, converted to il code, then loaded as an assembly.

    note: if lambda existed, when designed, than they probably would have been used, and the expression compiled at build instead of runtime.

    0 comments No comments