本文整理汇总了C#中Queue.LastOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.LastOrDefault方法的具体用法?C# Queue.LastOrDefault怎么用?C# Queue.LastOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.LastOrDefault方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DatabasePool
internal DatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias)
{
Hostname = hostname;
Port = port;
DatabaseName = databaseName;
DatabaseType = databaseType;
UserName = userName;
UserPassword = userPassword;
PoolSize = poolSize;
Alias = alias;
_connections = new Queue<Connection>();
for (int i = 0; i < poolSize; i++)
{
Connection connection = new Connection(Hostname, Port, databaseName, databaseType, userName, userPassword, alias, true);
_connections.Enqueue(connection);
}
//get release from last connection
var lastConnection = _connections.LastOrDefault();
if (lastConnection != null)
{
Release = lastConnection.Document.GetField<string>("OrientdbRelease");
}
}
示例2: 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();
}
示例3: QueueTest
public void QueueTest()
{
Queue<int> queue = new Queue<int>();
for (int i = 0; i < 10; ++i)
{
// queue.Enqueue(i);
}
var firstElement = queue.LastOrDefault();
Console.WriteLine("first: {0}", firstElement);
Queue<Element> queue2 = new Queue<Element>();
for (int i = 0; i < 10; ++i)
{
// queue.Enqueue(i);
}
var last = queue2.LastOrDefault();
Console.WriteLine("first: {0}", last);
}
示例4: CompleteInput
public IEnumerable<string> CompleteInput(Shell shell, string input)
{
var tokens = new Queue<string>(ShellCommandTokenizer.Tokenize(input));
var endsWithSpace = input.EndsWith(" ");
var result = FindMatchedCommands(tokens, endsWithSpace);
if (result.Commands.Count == 1)
{
var command = result.Commands.First();
if (tokens.Any() || (endsWithSpace && !result.IsTreeLevel))
{
var commandValue = command.Value as IShellCommand;
if (commandValue != null)
{
var completeResult = commandValue.Complete(shell, tokens.ToArray()) ?? new string[] { };
if (!(completeResult.Length == 1 && completeResult[0] == tokens.LastOrDefault() && endsWithSpace))
{
return completeResult;
}
}
return new string[] { };
}
return new[] { command.Key };
}
if (result.Commands.Count > 1 && !tokens.Any())
{
return result.Commands.Keys.OrderBy(x => x, StringComparer.OrdinalIgnoreCase).ToArray();
}
return new string[] { };
}
示例5: UpdateMomentumMotion
private IEnumerator UpdateMomentumMotion()
{
Queue<TimedValue> speedQueue = new Queue<TimedValue> ();
while (true) {
moSpeed.isOnGround = Physics.Linecast(compTrans.position, compTrans.position + Vector3.down);
float speed = moSpeed.isOnGround ? engine.curSpeed : speedQueue.LastOrDefault().value;
speedQueue.Enqueue(new TimedValue() { value = speed, time = Time.time} );
if (speedQueue.Count > momentumParams.queueNums) {
speedQueue.Dequeue();
}
List<float> recentSpeeds = speedQueue
.Where(s => Time.time - s.time < momentumParams.queueTime)
.Select(s => s.value).ToList();
float avg = recentSpeeds.Aggregate(0f, (m, s) => m = m + s / recentSpeeds.Count);
moSpeed.speed = avg;
yield return null;
}
}
示例6: IsValid
/// <summary>
/// Is valid path
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
private Boolean IsValid(DataPea pea, Queue<MoveNode> path)
{
// TODO: retry a path from a new position position
if (path.Peek().Position != pea.GridPosition)
return false;
var valid = new Queue<MoveNode>();
// Dummy previous node
valid.Enqueue(CreateNode(pea.GridPosition, MoveNode.Type.Walk, MoveNode.Direction.None).Value);
while (path.Count > 0) {
var node = path.Peek();
// Check validity of a node itself
if (!IsValid(node.Position))
return false;
// Check validity of moving from to the node
if (!IsValid(valid.LastOrDefault(), node))
return false;
valid.Enqueue(path.Dequeue());
}
// Remove dummy
valid.Dequeue();
// Restore path
while (valid.Count > 0)
path.Enqueue(valid.Dequeue());
return true;
}
示例7: Processed
public static void Processed(int height, int totalHeight, Queue<DateTime> lastLogs, Queue<int> lastHeights)
{
var lastLog = lastLogs.LastOrDefault();
if (DateTime.UtcNow - lastLog > TimeSpan.FromSeconds(10))
{
if (lastHeights.Count > 0)
{
var lastHeight = lastHeights.Peek();
var time = DateTimeOffset.UtcNow - lastLogs.Peek();
var downloadedSize = GetSize(lastHeight, height);
var remainingSize = GetSize(height, totalHeight);
var estimatedTime = downloadedSize == 0.0m ? TimeSpan.FromDays(999.0)
: TimeSpan.FromTicks((long)((remainingSize / downloadedSize) * time.Ticks));
_Trace.TraceInformation("Blocks {0}/{1} (estimate : {2})", height, totalHeight, Pretty(estimatedTime));
}
lastLogs.Enqueue(DateTime.UtcNow);
lastHeights.Enqueue(height);
while (lastLogs.Count > 20)
{
lastLogs.Dequeue();
lastHeights.Dequeue();
}
}
}