本文整理汇总了C#中Queue.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.FirstOrDefault方法的具体用法?C# Queue.FirstOrDefault怎么用?C# Queue.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.FirstOrDefault方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: produce
public static Program produce(Queue<Token> tokens)
{
ProgramBlock block = ProgramBlockFactory.produce(tokens);
if (tokens.Count != 0)
{
throw new ParsingException(tokens.FirstOrDefault().line + "; " + "No Symbol expected.Got '" + tokens.FirstOrDefault().tokenType + "'");
}
return new Program(block);
}
示例2: expect
public static Token expect(Queue<Token> tokens, TokenType exptectedSymbol)
{
if (tokens.FirstOrDefault().tokenType != exptectedSymbol)
{
throw new ParsingException(tokens.FirstOrDefault().line + "; " + "Unexpected Symbol. Expected '" +
exptectedSymbol + "', got '" + tokens.FirstOrDefault().tokenType + "'");
}
Token symbol = tokens.FirstOrDefault();
tokens.Dequeue();
return symbol;
}
示例3: optionalTerminator
public static void optionalTerminator(Queue<Token> tokens)
{
if (tokens.FirstOrDefault().tokenType == TokenType.END)
{
tokens.Dequeue();
}
}
示例4: produce
public static Statement produce(Queue<Token> tokens)
{
TokenType tokenType = tokens.FirstOrDefault().tokenType;
switch (tokenType)
{
case TokenType.IDENTIFIER:
Assignment assignment = AssignmentFactory.produce(tokens);
if (assignment == null)
{
Expression expression = FunctionCallFactory.produce(tokens);
if (expression != null)
{
return new ExpressionStatement(expression);
}
}
return assignment;
case TokenType.RETURN:
return ReturnStatementFactory.produce(tokens);
case TokenType.IF:
return IfFactory.produce(tokens);
case TokenType.WHILE:
return WhileFactory.produce(tokens);
default:
if (tokenType == TokenType.FOREACH)
{
return ForEachFactory.produce(tokens);
}
break;
}
return null;
}
示例5: Main
static void Main(string[] args)
{
Queue<string> qu = new Queue<string>();
qu.Enqueue("1");
qu.Enqueue("2");
qu.Enqueue("3");
var el = qu.FirstOrDefault();
var el1 = qu.Peek();
var el2 = qu.LastOrDefault();
}
示例6: produce
public static ProgramBlock produce(Queue<Token> tokens)
{
List<Statement> statements = new List<Statement>();
Token firstBlockToken = null;
if (tokens.Count != 0)
{
firstBlockToken = tokens.FirstOrDefault();
}
while (tokens.Count != 0)
{
Statement statement = StatementFactory.produce(tokens);
if(statement == null)
break;
statements.Add(statement);
}
return new ProgramBlock(firstBlockToken, statements);
}
示例7: GetPath
public static List<Tile> GetPath(Tile origin, Tile Target)
{
List<Tile> path = new List<Tile>();
Queue<Tile> internalData = new Queue<Tile>();
internalData.Enqueue(origin);
Point p = new Point((int)Target.current.x, (int)Target.current.y);
while (internalData.Count > 0)
{
double min = double.MaxValue;
Tile minTile = internalData.FirstOrDefault();
for (int i = 0; i < internalData.Count; i++)
{
var fitness = getH(Target, internalData.ElementAt(i)) + getG(origin, internalData.ElementAt(i));
if (min > fitness)
{
min = fitness;
minTile = internalData.ElementAt(i);
}
}
foreach (var u in path)
{
if (u.current.Contains(p))
{
for (int i = 0; i < path.Count - 1; i++)
{
//Debug.Log(u);
//Debug.Log(getH(Target, path.ElementAt(i)) + getG(origin, path.ElementAt(i)));
if (path.ElementAt(i) != null && path.ElementAt(i + 1) != null)
PathFinder.debugLineColl.Add(new Vector3Col(path.ElementAt(i).current.PositionVec, path.ElementAt(i + 1).current.PositionVec));
}
return path;
}
}
bool flag = true;
foreach (var tw in path)
if (tw.current.x == minTile.current.x && tw.current.y == minTile.current.y)
{
flag = false;
break;
}
if (flag)
{
path.Add(minTile);
}
var t = TileBase.GetLeft(internalData.Peek().current);
if (t != null && !internalData.Contains(t))
internalData.Enqueue(t);
t = TileBase.GetRight(internalData.Peek().current);
if (t != null && !internalData.Contains(t))
internalData.Enqueue(t);
t = TileBase.GetTop(internalData.Peek().current);
if (t != null && !internalData.Contains(t))
internalData.Enqueue(t);
t = TileBase.GetBottom(internalData.Peek().current);
if (t != null && !internalData.Contains(t))
internalData.Enqueue(t);
internalData.Dequeue();
}
return path;
}
示例8: MapChildren
/// <summary>
/// Map Children
/// </summary>
/// <param name="parent">parent</param>
/// <returns></returns>
private IEnumerable<MappedNode> MapChildren(MappedNode parent)
{
var models = new Queue<HtmlNode>(DistinguishProperties(parent.Model.ChildNodes));
var mapees = new Queue<HtmlNode>(parent.Mapee != null ? parent.Mapee.ChildNodes : Enumerable.Empty<HtmlNode>());
while (true)
{
var model = models.FirstOrDefault();
var mapee = mapees.FirstOrDefault();
if (model == null && mapee == null)
{
yield break;
}
if (model != null && mapee == null)
{
var property = propertyFactory.ParseTemplateReference(model);
if (property == null || models.Count > 1)
{
throw new InvalidOperationException("Skeleton is not a subset of the page");
}
else
{
yield return new MappedNode(parent, property, null);
yield break;
}
}
if (model == null && mapee != null)
{
while (mapees.Any())
{
yield return new MappedNode(parent, (PropertyDTO)null, mapees.Dequeue());
}
yield break;
}
var prop = propertyFactory.ParseTemplateReference(model);
if (prop != null)
{
models.Dequeue();
var nextModel = models.FirstOrDefault();
if (!mapees.Any() || AreEqual(nextModel, mapees.Peek()))
{
yield return new MappedNode(parent, prop, HtmlNode.CreateNode(string.Empty));
}
else
{
while (mapees.Any() && !AreEqual(nextModel, mapees.Peek()))
{
yield return new MappedNode(parent, prop, mapees.Dequeue());
}
}
if (mapees.Any())
{
continue;
}
else
{
yield break;
}
}
if (AreEqual(model, mapee))
{
yield return new MappedNode(parent, models.Dequeue(), mapees.Dequeue());
continue;
}
else
{
while (mapees.Any() && !AreEqual(model, mapees.Peek()))
{
yield return new MappedNode(parent, (PropertyDTO)null, mapees.Dequeue());
}
}
}
}