本文整理汇总了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]);
}
示例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);
}
示例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);
}