Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Cómo verificar si un conjunto de condiciones en una cadena es verdadero

Tengo una cadena que contiene expresiones de condición:

 "weight=65,age>18"

Quiero comprobar si la condición es verdadera.

Por ejemplo:

 int weight = 70; int age= 19; string conditions = "weight=65,age>18";

En el ejemplo anterior, la condición de weight es false y la condición age es true . Por lo tanto, el resultado debería ser false .

Quiero verificar la condición y regresar si se cumple la condición.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Está buscando un analizador , como una posible solución rápida, puede probar DataTable.Compute one:

 using System.Data; ... private static T RunWithVariables<T>( string formula, params (string name, object value)[] variables) { using DataTable table = new(); foreach (var (n, v) in variables) table.Columns.Add(n, v is null ? typeof(object) : v.GetType()); table.Rows.Add(); foreach (var (n, v) in variables) table.Rows[0][n] = v; table.Columns.Add("__Result", typeof(double)).Expression = formula ?? throw new ArgumentNullException(nameof(formula)); ; return (T)(Convert.ChangeType(table.Compute($"Min(__Result)", null), typeof(T))); }

Luego

 int weight = 70; int age = 19; string conditions = "weight=65,age>18"; var result = RunWithVariables<bool>(conditions.Replace(",", " and "), (nameof(weight), weight), (nameof(age), age));
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!