本文整理汇总了C#中Stack.Content方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Content方法的具体用法?C# Stack.Content怎么用?C# Stack.Content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.Content方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Calculate
public static decimal Calculate(this string[] tokens, decimal? x, string xname = "X")
{
int i = 0;
Stack<decimal> s = new Stack<decimal>(2);
while (i < tokens.Length)
{
decimal dectoken;
if (decimal.TryParse(tokens[i], out dectoken))
{
s.Push(dectoken);
}
else if (operators.Keys.Contains(tokens[i]))
{
Action<Stack<decimal>> action = operators[tokens[i]];
action(s);
}
else if (xname.Equals(tokens[i]))
{
if (x == null)
{
throw new Exception("Failed to calculate X.");
}
else
{
s.Push(x.Value);
}
}
else
{
throw new Exception(string.Format("Unknown type for token {0}", tokens[i]));
}
#if DEBUG
Console.WriteLine(string.Format("{0}\t{1}", s.Content(), tokens[i]));
#endif
i++;
}
if (s.Count != 1)
{
throw new Exception("Invalid expression.");
}
return s.Pop();
}
示例2: Calculate
public static ANXResult Calculate(this string[] tokens, string xname = "X")
{
int i = 0;
Stack<decimal?> s = new Stack<decimal?>(2);
Stack<decimal> i0 = new Stack<decimal>();
Stack<decimal> i1 = new Stack<decimal>();
while (i < tokens.Length)
{
decimal dectoken;
if (decimal.TryParse(tokens[i], out dectoken))
{
s.Push(dectoken);
}
else if (operators.Keys.Contains(tokens[i]))
{
Action<Stack<decimal?>, Stack<decimal>, Stack<decimal>> action = operators[tokens[i]];
action(s, i1, i0);
}
else if (xname.Equals(tokens[i]))
{
s.Push(null);
i1.Push(1);
i0.Push(0);
}
else
{
throw new Exception(string.Format("Unknown type for token {0}", tokens[i]));
}
#if DEBUG
Console.WriteLine(string.Format("{4}\t{0}\t{1}\t{2}\t{3}", s.Content(), tokens[i], i1.Content(), i0.Content(), i));
#endif
i++;
}
if (s.Count != 1)
{
throw new Exception("Invalid expression.");
}
decimal sc = s.Sum((d2) => { if (d2 != null) return d2.Value; else return 0; });
ANXResult result = new ANXResult() { Item1 = i1.Sum(), Item0 = i0.Sum() + sc };
return result;
}