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


C# Stack.Take方法代码示例

本文整理汇总了C#中Stack.Take方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Take方法的具体用法?C# Stack.Take怎么用?C# Stack.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stack的用法示例。


在下文中一共展示了Stack.Take方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateNotificationsForUser

        public void UpdateNotificationsForUser(IUser user, int maxNotificationBatchCountToCheck)
        {
            var notificationsUserPart = GetNotificationsUserPartOrThrow(user);

            var uncheckedNotificationsQuery = _contentManager
                .Query(VersionOptions.Published, Constants.NotificationBatchContentType)
                .Where<CommonPartRecord>(record => record.Id > notificationsUserPart.LastProcessedNotificationId);
            var uncheckedNotificationCount = uncheckedNotificationsQuery.Count();

            var notifications = _notificationService.FetchNotifications(user, Math.Min(uncheckedNotificationCount, maxNotificationBatchCountToCheck));

            var existingUserNotificationEntriesLookup = notificationsUserPart.RecentNotificationEntries.ToDictionary(entry => entry.NotificationId);
            var existingUserNotificationEntries = new Stack<NotificationUserEntry>(notificationsUserPart.RecentNotificationEntries.Reverse());
            foreach (var notification in notifications)
            {
                var notificationId = notification.ContentItem.Id;
                if (!existingUserNotificationEntriesLookup.ContainsKey(notificationId))
                {
                    existingUserNotificationEntries.Push(new NotificationUserEntry { NotificationId = notificationId });
                }
            }
            notificationsUserPart.RecentNotificationEntries = existingUserNotificationEntries.Take(maxNotificationBatchCountToCheck);

            var topNotification = uncheckedNotificationsQuery
                .OrderByDescending<CommonPartRecord>(record => record.Id)
                .Slice(1)
                .SingleOrDefault();
            if (topNotification != null)
            {
                notificationsUserPart.LastProcessedNotificationId = topNotification.Id;
            }
        }
开发者ID:Lombiq,项目名称:Orchard-User-Notifications,代码行数:32,代码来源:NotificationsToUserDispatcher.cs

示例2: PostMessages

        public void PostMessages(Stack<Tuple<ConsoleColor, string>> messages)
        {
            //post messages
            Console.SetCursorPosition(0, 20);
            var messagesToDisplay = messages.Take(5).ToList();
            int i = 0;
            foreach (var message in messages)
            {
                Console.SetCursorPosition(0, 20 + i);

                Console.ForegroundColor = message.Item1;
                Console.WriteLine(message.Item2.Trim() + new String(' ', Console.BufferWidth));
                if (i >= 4) { break; } else { i++; }

            }
            Console.SetCursorPosition(0, 0);
            Console.CursorVisible = false;
        }
开发者ID:sambeaven,项目名称:Rougelike,代码行数:18,代码来源:RLRenderer.cs

示例3: DirectoryListingEnumerator

        /// <summary>
        /// Initializes a new instance of the <see cref="DirectoryListingEnumerator"/> class.
        /// </summary>
        /// <param name="entries">The file system entries to enumerate</param>
        /// <param name="fileSystem">The file system of the file system entries</param>
        /// <param name="pathEntries">The path entries of the current directory</param>
        /// <param name="returnDotEntries"><code>true</code> when this enumerator should return the dot entries</param>
        public DirectoryListingEnumerator(IEnumerable<IUnixFileSystemEntry> entries, IUnixFileSystem fileSystem, Stack<IUnixDirectoryEntry> pathEntries, bool returnDotEntries)
        {
            _pathEntries = pathEntries;

            var topPathEntries = pathEntries.Take(3).ToList();

            switch (topPathEntries.Count)
            {
                case 0:
                    CurrentDirectory = fileSystem.Root;
                    ParentDirectory = GrandParentDirectory = null;
                    break;
                case 1:
                    CurrentDirectory = topPathEntries[0];
                    ParentDirectory = fileSystem.Root;
                    GrandParentDirectory = null;
                    break;
                case 2:
                    CurrentDirectory = topPathEntries[0];
                    ParentDirectory = topPathEntries[1];
                    GrandParentDirectory = fileSystem.Root;
                    break;
                default:
                    CurrentDirectory = topPathEntries[0];
                    ParentDirectory = topPathEntries[1];
                    GrandParentDirectory = topPathEntries[2];
                    break;
            }

            var dotEntries = new List<Tuple<IUnixDirectoryEntry, string>>();
            if (returnDotEntries)
            {
                dotEntries.Add(Tuple.Create(CurrentDirectory, "."));
                if (ParentDirectory != null)
                    dotEntries.Add(Tuple.Create(ParentDirectory, ".."));
            }

            _dotEntriesEnumerator = dotEntries.GetEnumerator();
            _entriesEnumerator = entries.GetEnumerator();
        }
开发者ID:FubarDevelopment,项目名称:FtpServer,代码行数:47,代码来源:DirectoryListingEnumerator.cs

示例4: EnsureStackSize

 private static Stack<GuildBankLogEntry> EnsureStackSize(Stack<GuildBankLogEntry> stack)
 {
     if (stack.Count <= MAX_ENTRIES) return stack;
     return (Stack<GuildBankLogEntry>)stack.Take(MAX_ENTRIES);
 }
开发者ID:pallmall,项目名称:WCell,代码行数:5,代码来源:GuildBankLog.cs

示例5: Parse

        protected override ParseTreeNode Parse(Lexer lexer, NonTerminal root)
        {
            IEnumerator<Token> tokens = lexer.GetEnumerator();

            var eof = !tokens.MoveNext();

            if (eof)
            {
                if (root.Rules.Any(r => r.IsNullable()))
                    return new ParseTreeNode(null, new Token(new Terminal(""), "", 0, 0));
                else
                    throw new ParseException("Empty string not matched by grammar");
            }

            Stack<ParseState> states = new Stack<ParseState>();
            states.Push(MakeStateState(root, Grammar));
            ParserAction action = ParserAction.Start;

            Stack<ParseTreeNode> nodes = new Stack<ParseTreeNode>();

            do
            {
                Production reduceProduction;
                ParseState shiftState;
                action = Action(states.Peek(), eof ? null : tokens.Current, out reduceProduction, out shiftState);

                switch (action)
                {
                    case ParserAction.Accept:
                        break;
                    case ParserAction.Error:
                        throw new ParseException(tokens.Current.ToString());
                    case ParserAction.Start:
                    default:
                        throw new NotImplementedException();

                    case ParserAction.Shift:
                        var newLeafNode = new ParseTreeNode(tokens.Current);
                        nodes.Push(newLeafNode);

                        states.Push(shiftState);
                        eof = !tokens.MoveNext();
                        break;

                    case ParserAction.Reduce:
                        var newNode = new ParseTreeNode(reduceProduction.Head);
                        var children = nodes.Take(reduceProduction.Body.Length).Reverse().Select((n, i) => new KeyValuePair<int, ParseTreeNode>(i, n));
                        foreach (var child in children)
                        {
                            child.Value.Parent = newNode;
                            nodes.Pop();

                            var bnfTerm = reduceProduction.Body[child.Key];
                            var terminal = bnfTerm as Terminal;

                            string match;
                            if (terminal != null)
                            {
                                if (!terminal.Match(child.Value.Token.Value, 0, out match))
                                    throw new ParseException("Unexpected crap");
                            }
                            else if (!reduceProduction.Body[child.Key].Equals(child.Value.NonTerminal))
                                throw new ParseException("Unexpected crap");
                        }

                        nodes.Push(newNode);

                        for (int i = 0; i < reduceProduction.Body.Length; i++)
                            states.Pop();
                        states.Push(Goto(states.Peek(), reduceProduction.Head));
                        break;
                }

            } while (action != ParserAction.Accept);

            if (nodes.Count != 1)
                throw new ParseException("o_0");

            return nodes.Pop();
        }
开发者ID:martindevans,项目名称:Hermes,代码行数:80,代码来源:LRParserBase.cs

示例6: CalculateEntropy

 /// <summary>
 /// Find the Cumulative Entropy over the last second worth of frames
 /// </summary>
 /// <param name="frameHistory">A stack of frames (i.e in reverse chronological order)</param>
 /// <returns>The cumulative entropy over the last second</returns>
 public double CalculateEntropy(Stack<List<Vector3D>> frameHistory)
 {
     // choose only the last second worth of frames
     return frameHistory.Take(framesPerSecond+1).Aggregate(EntropyAcc.Zero, EntropyAcc.Aggregate).CumulativeEntropy;
 }
开发者ID:smanoharan,项目名称:314Kinect,代码行数:10,代码来源:EntropyMonitor.cs

示例7: GetPath

 public List<TreeItem> GetPath(TreeItem root, bool leaveOutRootInReturnValue)
 {
     Stack<TreeItem> stack = new Stack<TreeItem>();
     this.GetItemPath(root, ref stack);
     return leaveOutRootInReturnValue ? stack.Take(stack.Count - 1).Reverse().ToList() : stack.Reverse().ToList();
 }
开发者ID:Shraddha512,项目名称:ICSE-2011-FireDetective,代码行数:6,代码来源:ItemsTreeView.cs


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