本文整理汇总了C#中Queue.Single方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Single方法的具体用法?C# Queue.Single怎么用?C# Queue.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.Single方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadLine
public void ReadLine(string text)
{
if (text.Trim().StartsWith("#")) return;
var tokens = new Queue<string>(StringTokenizer.Tokenize(text.Replace(',', ' ')));
if (tokens.Count == 1)
{
if (_readerAction == null)
{
throw new InvalidSyntaxException("Not enough tokens in the command line");
}
_readerAction(tokens.First());
return;
}
_lastName = null;
_readerAction = null;
if (tokens.Count() < 3)
{
throw new InvalidSyntaxException("Not enough tokens in the command line");
}
var key = tokens.Dequeue();
var verb = tokens.Dequeue();
if (key == "ordered")
{
handleOrderedSet(tokens, verb);
return;
}
switch (verb)
{
case "is":
if (tokens.Count > 1) throw new InvalidSyntaxException("Only one name can appear on the right side of the 'is' verb");
_registration.Alias(tokens.Dequeue(), key);
break;
case "requires":
tokens.Each(name => _registration.Dependency(key, name));
break;
case "extends":
if (tokens.Count > 1) throw new InvalidSyntaxException("Only one name can appear on the right side of the 'extends' verb");
_registration.Extension(key, tokens.Single());
break;
case "includes":
tokens.Each(name => _registration.AddToSet(key, name));
break;
case "preceeds":
tokens.Each(name => _registration.Preceeding(key, name));
break;
default:
string message = "'{0}' is an invalid verb".ToFormat(verb);
throw new InvalidSyntaxException(message);
}
}
示例2: QueueExtensions_Single_ThrowsExceptionIfQueueIsEmpty
public void QueueExtensions_Single_ThrowsExceptionIfQueueIsEmpty()
{
var queue = new Queue<Int32>();
Assert.That(() => queue.Single(),
Throws.TypeOf<InvalidOperationException>());
}
示例3: QueueExtensions_Single_ThrowsExceptionIfQueueHasMultipleItems
public void QueueExtensions_Single_ThrowsExceptionIfQueueHasMultipleItems()
{
var queue = new Queue<Int32>();
queue.Enqueue(1);
queue.Enqueue(2);
Assert.That(() => queue.Single(),
Throws.TypeOf<InvalidOperationException>());
}
示例4: QueueExtensions_Single_ReturnsSingleItemInQueue
public void QueueExtensions_Single_ReturnsSingleItemInQueue()
{
var queue = new Queue<Int32>();
queue.Enqueue(4);
var result = queue.Single();
TheResultingValue(result).ShouldBe(4);
}
示例5: QueueExtensions_Single_ThrowsExceptionIfQueueHasMultipleItems
public void QueueExtensions_Single_ThrowsExceptionIfQueueHasMultipleItems()
{
var queue = new Queue<Int32>();
queue.Enqueue(1);
queue.Enqueue(2);
queue.Single();
}
示例6: QueueExtensions_Single_ThrowsExceptionIfQueueIsEmpty
public void QueueExtensions_Single_ThrowsExceptionIfQueueIsEmpty()
{
var queue = new Queue<Int32>();
queue.Single();
}