本文整理汇总了C#中System.Linq.Index方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.Index方法的具体用法?C# System.Linq.Index怎么用?C# System.Linq.Index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.Index方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_allow_starting_at_another_index
public void Should_allow_starting_at_another_index()
{
var strings = new[] {"A", "B", "C"};
var result = strings.Index(47, (x,i) => new { Index = i, Value = x});
Assert.IsNotNull(result);
var resultArray = result.ToArray();
Assert.AreEqual(strings.Length, resultArray.Length);
Assert.AreEqual(resultArray[0].Index, 47);
Assert.AreEqual(resultArray[1].Index, 48);
}
示例2: Should_return_an_indexed_enumeration_of_a_new_type
public void Should_return_an_indexed_enumeration_of_a_new_type()
{
var strings = new[] {"A", "B", "C"};
var result = strings.Index((x,i) => new { Index = i, Value = x});
Assert.IsNotNull(result);
var resultArray = result.ToArray();
Assert.AreEqual(strings.Length, resultArray.Length);
Assert.AreEqual(resultArray[0].Index, 0);
Assert.AreEqual(resultArray[1].Index, 1);
}
示例3: StringRepresentations
public void StringRepresentations()
{
var infos = from member in new[] { null, "foo" }
from file in new[] { null, "bar" }
from line in new[] { 0, 42 }
select new CallerInfo(member, file, line);
var expectations = new[]
{
"<?member>@<?filename>:0",
"<?member>@<?filename>:42",
"<?member>@bar:0",
"<?member>@bar:42",
"[email protected]<?filename>:0",
"[email protected]<?filename>:42",
"[email protected]:0",
"[email protected]:42",
};
var assertions = // TODO Zip instead of joining when on .NET 4
from info in infos.Index()
join exp in expectations.Index() on info.Key equals exp.Key
orderby info.Key
select new
{
Expected = exp.Value,
Actual = info.Value.ToString(),
};
foreach (var a in assertions)
Assert.Equal(a.Expected, a.Actual);
}