当前位置: 首页>>代码示例>>C#>>正文


C# Queue.LastOrDefault方法代码示例

本文整理汇总了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");
            }
        }
开发者ID:workshare,项目名称:OrientDB-NET.binary,代码行数:27,代码来源:DatabasePool.cs

示例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();

        }
开发者ID:kokushkin,项目名称:TestRepository,代码行数:13,代码来源:Program.cs

示例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);
        }
开发者ID:gordonlee,项目名称:testlab,代码行数:20,代码来源:Program.cs

示例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[] { };
        }
开发者ID:RaveNoX,项目名称:ConsoleShell,代码行数:38,代码来源:ShellCommandsContainer.cs

示例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;
        }
    }
开发者ID:n0mimono,项目名称:my-motorbike,代码行数:24,代码来源:Motorbike.cs

示例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;
        }
开发者ID:SleeplessByte,项目名称:playwithyourpeas,代码行数:37,代码来源:PeaController.cs

示例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();
                }
            }
        }
开发者ID:bijakatlykkex,项目名称:NBitcoin.Indexer,代码行数:25,代码来源:IndexerTrace.cs


注:本文中的Queue.LastOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。