本文整理汇总了C#中IExpression.Calculate方法的典型用法代码示例。如果您正苦于以下问题:C# IExpression.Calculate方法的具体用法?C# IExpression.Calculate怎么用?C# IExpression.Calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IExpression
的用法示例。
在下文中一共展示了IExpression.Calculate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mul
/// <summary>
/// Multiplies <paramref name="vector"/> by <paramref name="number"/>.
/// </summary>
/// <param name="vector">The vector.</param>
/// <param name="number">The number.</param>
/// <param name="parameters">An object that contains all parameters and functions for expressions.</param>
/// <returns>The product of matrices.</returns>
public static Vector Mul(this Vector vector, IExpression number, ExpressionParameters parameters)
{
var n = (double)number.Calculate(parameters);
#if NET40_OR_GREATER
var numbers = (from num in vector.Arguments.AsParallel().AsOrdered()
select new Number((double)num.Calculate(parameters) * n))
.ToArray();
#else
var numbers = (from num in vector.Arguments
select new Number((double)num.Calculate(parameters) * n))
.ToArray();
#endif
return new Vector(numbers);
}
示例2: Generate
public void Generate(string strExp)
{
expression = parser.Parse(strExp);
if (!expression.ResultType.HasFlag(ExpressionResultType.Boolean))
throw new InvalidOperationException();
expressions = parser.ConvertExpressionToCollection(expression);
parameters = parser.GetParameters(strExp);
table = new List<TruthTableRowViewModel>();
var parametersCount = parameters.Count();
for (int i = (int)Math.Pow(2, parametersCount) - 1; i >= 0; i--)
{
SetBits(i, parametersCount);
var b = (bool)expression.Calculate(parameters);
var row = new TruthTableRowViewModel(parametersCount, expressions.Count());
row.Index = (int)Math.Pow(2, parametersCount) - i;
for (int j = 0; j < parametersCount; j++)
row.VarsValues[j] = (bool)parameters[parameters.ElementAt(j).Key];
for (int j = 0; j < expressions.Count() - 1; j++)
row.Values[j] = (bool)expressions.ElementAt(j).Calculate(parameters);
if (expressions.Count() != 0)
row.Result = b;
table.Add(row);
}
}