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


C# Stack.Skip方法代码示例

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


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

示例1: RelativePathFor

		public string RelativePathFor(IFileSystemItem file)
		{
			Stack<string> path = new Stack<string>();
			IFileSystemItem current = file;
			do
			{
				path.Push(current.Name);
				current = current.Parent;
			}
			while (current != _root);
			return path.Skip(1).Aggregate(path.Peek(), (acc, item) => acc + @"\" + item);
		}
开发者ID:Galigator,项目名称:db4o,代码行数:12,代码来源:FileFinder.cs

示例2: MaxArray2

        int[] MaxArray2(int[] num, int len)
        {
            int drop = num.Length - len;

            Stack<int> st = new Stack<int>();

            foreach(var d in num)
            {
                while (st.Count() > 0 && drop > 0 && d > st.Peek())
                {
                    st.Pop();
                    drop--;
                }
                st.Push(d);
            }

            return st.Skip(st.Count() - len).Reverse().ToArray();            
        }
开发者ID:aribeth97,项目名称:leetcode-CSharp,代码行数:18,代码来源:Solution321.cs

示例3: Parse

        private void Parse(string template, SemanticModel semanticModel, Stack<Context> context, int offset)
        {
            var stream = new Stream(template, offset);

            do
            {
                if (ParseCodeBlock(stream, semanticModel, context)) continue;
                if (ParseDollar(stream, semanticModel, context)) continue;
                if (ParseString(stream, semanticModel, context)) continue;
                if (ParseComment(stream, semanticModel, context)) continue;
                if (ParseNumber(stream, semanticModel)) continue;
                if (ParseOperators(stream, semanticModel)) continue;
                if (ParseKeywords(stream, semanticModel)) continue;

                semanticModel.Tokens.AddBrace(stream);
            }
            while (stream.Advance());

            var parent = context.Skip(1).FirstOrDefault();
            semanticModel.ContextSpans.Add(context.Peek(), parent, ContextType.Template, offset, stream.Position);
        }
开发者ID:Kymeric,项目名称:Typewriter,代码行数:21,代码来源:TemplateLexer.cs

示例4: ParseDollar

        private bool ParseDollar(Stream stream, SemanticModel semanticModel, Stack<Context> context, int depth)
        {
            if (stream.Current == '$')
            {
                var identifier = GetIdentifier(stream, semanticModel, context);

                if (identifier != null)
                {
                    var classification = GetPropertyClassification(depth);

                    if (identifier.IsParent)
                    {
                        var parent = context.Skip(1).FirstOrDefault()?.Name.ToLowerInvariant();
                        semanticModel.Tokens.Add(classification, stream.Position, identifier.Name.Length + 1, identifier.QuickInfo.Replace("$parent", parent));
                        stream.Advance(identifier.Name.Length);

                        var current = context.Pop();

                        //ParseDot(stream, semanticModel, context, depth); // identifier
                        ParseBlock(stream, semanticModel, context, depth); // template

                        context.Push(current);
                    }
                    else
                    {
                        semanticModel.Tokens.Add(classification, stream.Position, identifier.Name.Length + 1, identifier.QuickInfo);
                        stream.Advance(identifier.Name.Length);

                        if (identifier.IsCollection)
                        {
                            context.Push(_contexts.Find(identifier.Context));

                            ParseFilter(stream, semanticModel, context, depth);
                            ParseBlock(stream, semanticModel, context, depth); // template

                            context.Pop();

                            ParseBlock(stream, semanticModel, context, depth); // separator
                        }
                        else if (identifier.IsBoolean)
                        {
                            ParseBlock(stream, semanticModel, context, depth); // true
                            ParseBlock(stream, semanticModel, context, depth); // false
                        }
                        else if (identifier.HasContext)
                        {
                            context.Push(_contexts.Find(identifier.Context));

                            //ParseDot(stream, semanticModel, context, depth); // identifier
                            ParseBlock(stream, semanticModel, context, depth); // template

                            context.Pop();
                        }
                    }

                    return true;
                }
            }

            return false;
        }
开发者ID:floatas,项目名称:Typewriter,代码行数:61,代码来源:TemplateLexer.cs

示例5: ParseStatements


//.........这里部分代码省略.........
                var pdt = (DoubleTypeInstruction*)ins;
                var pcl = (CallInstruction      *)ins;
                var pps = (PushInstruction      *)ins;
                var pse = (SetInstruction       *)ins;
                var pbr = (GotoInstruction      *)ins;
                var pbk = (BreakInstruction     *)ins;

                var st = ins->SingleType;
                var dt = ins->DoubleType;
                var cl = ins->Call      ;
                var ps = ins->Push      ;
                var se = ins->Set       ;

                var t1 = ins->Kind() == InstructionKind.SingleType ? st.Type
                      : (ins->Kind() == InstructionKind.DoubleType ? dt.Types.Type1 : 0);
                var t2 = ins->Kind() == InstructionKind.DoubleType ? dt.Types.Type2
                      : (ins->Kind() == InstructionKind.SingleType ? st.Type        : 0);
                #endregion

                switch (ins->Code())
                {
                    #region dup, pop
                    case OpCode.Dup:
                        var normal = true;
                        if (i < instr.Length - 1 && instr[i + 1]->OpCode == OpCode.Push)
                        {
                            var n = &instr[i + 1]->Push;
                            var t = ((Reference*)&n->ValueRest)->Type;

                            if (t == VariableType.Array && stack.Count > 1)
                            {
                                normal = false;

                                stack.Push(stack.Skip(1).First()); // second item
                                stack.Push(stack.Skip(1).First()); // first  item (original stack top)
                            }
                        }

                        if (!normal)
                            break;

                        if (!dupTars.Contains(stack.Peek()))
                            dupTars.Add(stack.Peek());

                        if (stack.Peek().WalkExprTree(e => e is CallExpression).Any(_ => _))
                        {
                            stack.Push(new UnaryOperatorExpression
                            {
                                Input        = stack.Peek(),
                                Operator     = UnaryOperator.Duplicate,
                                OriginalType = stack.Peek().ReturnType,
                                ReturnType   = st.Type
                            });

                            //AddStmt(new DupStatement());
                        }
                        else
                            stack.Push(stack.Peek());
                        break;
                    case OpCode.Pop:
                        if (stack.Count > 0 && stack.Peek() is CallExpression)
                            AddStmt(new CallStatement
                            {
                                Call = stack.Pop() as CallExpression
                            });
                        else
开发者ID:WarlockD,项目名称:Altar.NET,代码行数:67,代码来源:Decompiler.cs

示例6: ExpandSelector

        public static CssSelector ExpandSelector(StyleRule rule)
        {
            var parts = new Stack<CssSelector>();

            parts.Push(rule.Selector);

            StyleRule current = rule;

            while ((current = current.Parent as StyleRule) != null)
            {
                parts.Push(current.Selector);

                if (parts.Count > 6)
                {
                    throw new Exception(string.Format("May not nest more than 6 levels deep. Was {0}. ", string.Join(" ", parts)));
                }
            }

            var i = 0;

            var sb = new StringBuilder();

            foreach (var selector in parts)
            {
                if (selector.Contains("&"))
                {
                    var x = selector.ToString().Replace("&", sb.ToString());

                    sb.Clear();

                    sb.Append(x);

                    i++;

                    continue;
                }

                if (i != 0) sb.Append(" ");

                i++;

                // h1, h2, h3

                if (selector.Count > 1)
                {
                    var parentSelector = sb.ToString();

                    sb.Clear();

                    var c = GetSelector(parts.Skip(i));

                    var q = 0;

                    foreach (var a in selector)
                    {
                        if (q != 0) sb.Append(", ");

                        sb.Append(parentSelector + a);

                        if (c != null)
                        {
                            sb.Append(" " + c);
                        }

                        q++;
                    }

                    break;
                }
                else
                {
                    sb.Append(selector);
                }
            }

            return new CssSelector(sb.ToString());
        }
开发者ID:carbon,项目名称:Css,代码行数:77,代码来源:CssWriter.cs

示例7: Walk

        private List<Path> Walk(DirectoryPath rootPath, Stack<Node> segments)
        {
            var results = new List<Path>();
            var segment = segments.Pop();

            var expression = new Regex("^" + segment.Render() + "$", _options);
            var isDirectoryWildcard = false;

            if (segment is WildcardSegmentNode)
            {
                segments.Push(segment);
                isDirectoryWildcard = true;
            }

            // Get all files and folders.
            var root = _fileSystem.GetDirectory(rootPath);
            if (!root.Exists)
            {
                return results;
            }

            foreach (var directory in root.GetDirectories("*", SearchScope.Current))
            {
                var part = directory.Path.FullPath.Substring(root.Path.FullPath.Length + 1);
                var pathTest = expression.IsMatch(part);

                var subWalkCount = 0;

                if (isDirectoryWildcard)
                {
                    // Walk recursivly down the segment.
                    var nextSegments = new Stack<Node>(segments.Reverse());
                    var subwalkResult = Walk(directory.Path, nextSegments);
                    if (subwalkResult.Count > 0)
                    {
                        results.AddRange(subwalkResult);
                    }

                    subWalkCount++;
                }

                // Check without directory wildcard.
                if (segments.Count > subWalkCount && (subWalkCount == 1 || pathTest))
                {
                    // Walk the next segment in the list.
                    var nextSegments = new Stack<Node>(segments.Skip(subWalkCount).Reverse());
                    var subwalkResult = Walk(directory.Path, nextSegments);
                    if (subwalkResult.Count > 0)
                    {
                        results.AddRange(subwalkResult);
                    }
                }

                // Got a match?
                if (pathTest && segments.Count == 0)
                {
                    results.Add(directory.Path);
                }
            }

            foreach (var file in root.GetFiles("*", SearchScope.Current))
            {
                var part = file.Path.FullPath.Substring(root.Path.FullPath.Length + 1);
                var pathTest = expression.IsMatch(part);

                // Got a match?
                if (pathTest && segments.Count == 0)
                {
                    results.Add(file.Path);
                }
                else if(pathTest)
                {
                    /////////////////////////////////////////////////////////////B
                    // We got a match, but we still have segments left.
                    // Is the next part a directory wild card?
                    /////////////////////////////////////////////////////////////

                    var nextNode = segments.Peek();
                    if (nextNode is WildcardSegmentNode)
                    {
                        var nextSegments = new Stack<Node>(segments.Skip(1).Reverse());
                        var subwalkResult = Walk(root.Path, nextSegments);
                        if (subwalkResult.Count > 0)
                        {
                            results.AddRange(subwalkResult);
                        }
                    }
                }
            }
            return results;
        }
开发者ID:DNIDNL,项目名称:hadouken,代码行数:91,代码来源:Globber.cs

示例8: CheckIfTrackForCrossedOldTrack

        private static bool CheckIfTrackForCrossedOldTrack(Stack<Iteration> iterations, Iteration currentIteration, Car currentCar)
        {
            const int skipFirst = 2;
            if (iterations.Count <= skipFirst)
            {
                return false;
            }

            var currentTrack = currentIteration.Line;
            var currentPosition = currentCar.Position;
            var result = iterations
                   .Skip(1)
                   .Any(it => FilterCheckIfTrackForCrossedOldTrack(currentTrack, it.Line, currentPosition));

            return result;
        }
开发者ID:WinstonSmith77,项目名称:vertrackt,代码行数:16,代码来源:Solver.cs


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