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


C# System.Collections.Generic.ElementAt方法代码示例

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


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

示例1: Accumulate_WithTwoEnumerations_AccumulatesOneIntoTheOther

        public void Accumulate_WithTwoEnumerations_AccumulatesOneIntoTheOther()
        {
            // arrange
            var containers = new[] { new KeyValuePair<int, List<string>>(0, new List<string>()), new KeyValuePair<int, List<string>>(1, new List<string>()), new KeyValuePair<int, List<string>>(2, new List<string>()), new KeyValuePair<int, List<string>>(3, new List<string>()) };
            var items = new[] {new KeyValuePair<int, string>(1, "A"), new KeyValuePair<int, string>(1, "B"), new KeyValuePair<int, string>(3, "C")};

            // act
            containers.Accumulate(items, container => container.Key, item => item.Key, (container, item) => container.Value.Add(item.Value));

            // assert
            Assert.AreEqual(0, containers.First().Value.Count);
            var secondContainer = containers.ElementAt(1);
            Assert.AreEqual(2, secondContainer.Value.Count);
            Assert.AreEqual("A", secondContainer.Value[0]);
            Assert.AreEqual("B", secondContainer.Value[1]);
            Assert.AreEqual(0, containers.ElementAt(2).Value.Count);
            var fourthContainer = containers.ElementAt(3);
            Assert.AreEqual(1, fourthContainer.Value.Count);
            Assert.AreEqual("C", fourthContainer.Value[0]);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:20,代码来源:CollectionExtensionsTests.cs

示例2: BuildParametizedQuantifierNode

        public static Node BuildParametizedQuantifierNode(Token startToken, TreeBuilderState state)
        {
            var acceptedQuantifierTokenTypes = new[]
            {
                TokenType.Number,
                TokenType.ParametizedQuantifierRangeSeparator,
                TokenType.ParametizedQuantifierEnd
            };

            var remainingQuantifierTokens = state.ProcessingState.Tokens
                .DequeueWhile(t => acceptedQuantifierTokenTypes.Contains(t.Type));

            var quantifierTokens = new[] { startToken }.Concat(remainingQuantifierTokens);

            int? min;
            int? max;

            var quantifierTokenTypes = quantifierTokens.Select(t => t.Type);
            if (quantifierTokenTypes.SequenceEqual(new[]
                {
                    TokenType.ParametizedQuantifierStart,
                    TokenType.Number,
                    TokenType.ParametizedQuantifierRangeSeparator,
                    TokenType.Number,
                    TokenType.ParametizedQuantifierEnd
                }))
            {
                min = int.Parse(quantifierTokens.ElementAt(1).Data);
                max = int.Parse(quantifierTokens.ElementAt(3).Data);
            }
            else if (quantifierTokenTypes.SequenceEqual(new[]
                {
                    TokenType.ParametizedQuantifierStart,
                    TokenType.ParametizedQuantifierRangeSeparator,
                    TokenType.Number,
                    TokenType.ParametizedQuantifierEnd
                }))
            {
                min = null;
                max = int.Parse(quantifierTokens.ElementAt(2).Data);
            }
            else if (quantifierTokenTypes.SequenceEqual(new[]
                {
                    TokenType.ParametizedQuantifierStart,
                    TokenType.Number,
                    TokenType.ParametizedQuantifierRangeSeparator,
                    TokenType.ParametizedQuantifierEnd
                }))
            {
                min = int.Parse(quantifierTokens.ElementAt(1).Data);
                max = null;
            }
            else if (quantifierTokenTypes.SequenceEqual(new[]
                {
                    TokenType.ParametizedQuantifierStart,
                    TokenType.Number,
                    TokenType.ParametizedQuantifierEnd
                }))
            {
                min = int.Parse(quantifierTokens.ElementAt(1).Data);
                max = min;
            }
            else
            {
                return new LiteralNode(
                    Token.GetData(quantifierTokens),
                    startToken.StartIndex
                );
            }

            return BuildQuantifierNode(quantifierTokens, state, min, max);
        }
开发者ID:tathamoddie,项目名称:RegexAnalyzer,代码行数:72,代码来源:QuantifierNodeBuilder.cs

示例3: should_get_nth_element_using_element_at

        public void should_get_nth_element_using_element_at()
        {
            var sequence = new[] { 1, 2, 3, 4, 5 };

            int thirdElement = sequence.ElementAt(2);

            // please update variable value to fix the test.
            const int expectedThirdElement = 0;

            Assert.Equal(expectedThirdElement, thirdElement);
        }
开发者ID:chenbojian,项目名称:01_NewbieVillage,代码行数:11,代码来源:24_LinqBasics.cs


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