本文整理汇总了C#中Stack.Single方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Single方法的具体用法?C# Stack.Single怎么用?C# Stack.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.Single方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NumberedRepeat
private static NFA NumberedRepeat(NFA nfa, int minRepetitions, int maxRepetitions)
{
// To create a suitable expression, the special case of infinite max repetitions
// must be separately handled.
bool infiniteMax = false;
if (maxRepetitions == int.MaxValue)
{
infiniteMax = true;
maxRepetitions = minRepetitions;
}
else if (maxRepetitions < minRepetitions)
{
maxRepetitions = minRepetitions;
}
// Copy the NFA max repetitions times, link them together.
NFA output = nfa.Copy();
var epsilonLinkStates = new Stack<NFA.State>();
for (int i = 1; i < maxRepetitions; ++i)
{
NFA newNfa = nfa.Copy();
if (i >= minRepetitions || (infiniteMax && i == maxRepetitions - 1 ))
{
epsilonLinkStates.Push(newNfa.StartState);
}
output = And(output, newNfa);
}
if (infiniteMax)
{
// Use Single to force an exception if this has gone astray
var finalState = epsilonLinkStates.Single();
// Make a little epsilon loop from the final accept state to the start state of the final state
output.Transitions.Add(new Transition<NFA.State>(output.States.Single(f => f.AcceptState), finalState));
}
else
{
// Add epsilon transitions from accept to beginning states of NFAs in the chain
var acceptState = output.States.Single(f => f.AcceptState);
while (epsilonLinkStates.Any())
{
output.Transitions.Add(new Transition<NFA.State>(epsilonLinkStates.Pop(),
acceptState));
}
}
return output;
}
示例2: StackExtensions_Single_ThrowsExceptionIfStackIsEmpty
public void StackExtensions_Single_ThrowsExceptionIfStackIsEmpty()
{
var stack = new Stack<Int32>();
Assert.That(() => stack.Single(),
Throws.TypeOf<InvalidOperationException>());
}
示例3: StackExtensions_Single_ThrowsExceptionIfStackHasMultipleItems
public void StackExtensions_Single_ThrowsExceptionIfStackHasMultipleItems()
{
var stack = new Stack<Int32>();
stack.Push(1);
stack.Push(2);
Assert.That(() => stack.Single(),
Throws.TypeOf<InvalidOperationException>());
}
示例4: StackExtensions_Single_ReturnsSingleItemInStack
public void StackExtensions_Single_ReturnsSingleItemInStack()
{
var stack = new Stack<Int32>();
stack.Push(4);
var result = stack.Single();
TheResultingValue(result).ShouldBe(4);
}
示例5: StackExtensions_Single_ThrowsExceptionIfStackHasMultipleItems
public void StackExtensions_Single_ThrowsExceptionIfStackHasMultipleItems()
{
var stack = new Stack<Int32>();
stack.Push(1);
stack.Push(2);
stack.Single();
}
示例6: StackExtensions_Single_ThrowsExceptionIfStackIsEmpty
public void StackExtensions_Single_ThrowsExceptionIfStackIsEmpty()
{
var stack = new Stack<Int32>();
stack.Single();
}