public static double Evaluate(string expression)
{
return (double)new System.Xml.XPath.XPathDocument
(new System.IO.StringReader("<r/>")).CreateNavigator().Evaluate
(string.Format("number({0})", new
System.Text.RegularExpressions.Regex(@"([\+\-\*])").Replace(expression, " ${1} ")
.Replace("/", " div ").Replace("%", " mod ")));
}
In Method 1 System.Text.RegularExpressions.Regex helps in giving space between operator and also to replace "/" operator to div and "%" operator to mod. XPathNavigator.Evaluate method evaluates the string representing an XPath expression and returns the typed result.
Method 2 :
public static double Evaluate(string expression)
{
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("expression", string.Empty.GetType(), expression);
System.Data.DataRow row = table.NewRow();
table.Rows.Add(row);
return double.Parse((string)row["expression"]);
}
In Method 2 DataColumn.Expression in System.Data.DataTable is used to create a default row with required expression. Thereby DataTable calculate the values in a column and gives the evaluated result. Resultant datatype for Evaluate function in method 2 can changed to evaluate boolean expression and to get boolean results.
System.Console.WriteLine(Evaluate("2 * 4"));
分享到:
相关推荐
How To... Evaluate SeqCap EZ Target Enrichment Data.pdf
This book will help you learn how to choose a model for your problem, how to evaluate the performance of your models, and how you can use C# to build machine learning models for your future projects....
MIT科研团队在2020年isscc上有关深度学习处理器的教程,包含视频和文档资料,欢迎下载学习
This white paper introduces server farms and how you can use them to address scalability and reliability issues. It explains how you can use Microsoft® Office SharePoint® Server 2007 and Windows® ...
怎样检验神经网络_(深度学习)__How_to_evaluate_neural_networks_(deep_learning)
How NOT To Evaluate Your Dialogue System- An Empirical Study of Unsupervised Evaluation Metrics for Dialogue Response Generation.pdf
EVALUATE宏表函数使用汇总EVALUATE宏表函数使用汇总EVALUATE宏表函数使用汇总
Excel2021中Evaluate函数介绍.docx
In this paper, we evaluate these extensions with respect to the realm of scientific computing and compare them with C++ templates. At the heart of our comparison are the set and relation classes from...
The interpreter extends standard of C# language with extra features which simplify the use of C# for scripting needs (more...). paxScript.NET is implemented as a .NET component ( paxscript-net.dll) ...
how to build the same app, two different ways, so you can compare and contrast and evaluate what’s best for you and your team. After that, we’ll discuss how to write complex, advanced components ...
how to build the same app, two different ways, so you can compare and contrast and evaluate what’s best for you and your team. After that, we’ll discuss how to write complex, advanced components ...
IDL evaluate
C语言代码练习,程序员:EvaluateExpression
这个题目是我今天发现的,感谢鱼儿提供的EVALUATE()的单元格区域的引用方法.
PB describe Evaluate LookUpDisplay用法,仅供参考!
EVALUATE宏表函数妙用,帮助你更好的使用Excel
Evaluate-mathematical-expression codewar题解
place, we evaluate if it’s worthy to move to microservices, and what would be a good way to do so. How should we communicate these different pieces? Then we can describe and introduce the event-...
We describe and evaluate two ONOS prototypes. The first version implemented core features: a distributed, butlogicallycentralized,globalnetworkview;scale-out;and fault tolerance. The second version ...