WPF problem

Leon NG 101 Reputation points
2023-03-01T04:24:00.12+00:00

Hi there,

I'm trying to read a csv to get a formula, e.g. A+B+C or A*B or (A-C)/B (A, B, C is input).

Then, I input A, B, C value in UI, and it can calculate the result automatedly.

Is this possible to do?

Thank you.

Best Regards,

Leon

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,670 questions
C#
C#
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,234 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K Reputation points
    2023-03-01T06:32:02.25+00:00

    In case of elementary operations, it is possible to use a DataTable. For example:

    string formula = "(A-C)/B";
    double A = 123.45;
    double B = -0.7;
    double C = 9.8;
    
    var dt = new DataTable( );
    
    dt.Columns.Add( "A", typeof( double ) );
    dt.Columns.Add( "B", typeof( double ) );
    dt.Columns.Add( "C", typeof( double ) );
    var rc = dt.Columns.Add( "R", typeof( double ), formula );
    dt.Rows.Add( A, B, C );
    
    double result = (double)dt.Rows[0][rc];
    
    0 comments No comments

0 additional answers

Sort by: Most helpful