本文整理汇总了C#中System.Collections.Generic.Distinct方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Distinct方法的具体用法?C# System.Collections.Generic.Distinct怎么用?C# System.Collections.Generic.Distinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.Distinct方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Distinct
public void Distinct()
{
int[] numbers = new[] {1, 2, 1, 3, 4, 5, 5, 3};
Assert.AreEqual(5, numbers.Distinct((a, b) => a == b).Count());
Assert.AreEqual(new[] { 1, 2, 3, 4, 5 }, numbers.Distinct((a, b) => a == b).ToArray());
}
示例2: should_return_distinct_items
public void should_return_distinct_items()
{
var jedis = new[]
{
new Jedi("Mace Windu"),
new Jedi("Mace Windu"),
new Jedi("Luke Skywalker"),
new Jedi("Yoda"),
new Jedi("Yoda"),
};
IEnumerable<Jedi> distinct = jedis.Distinct((j1, j2) => j1.Name == j2.Name);
distinct.Count().ShouldBe(3);
}
示例3: ChecksumFXAssemblies
public void ChecksumFXAssemblies()
{
var paths = new[]
{
typeof(object).GetTypeInfo().Assembly.Location,
typeof(Enumerable).GetTypeInfo().Assembly.Location,
typeof(Linq.Expressions.Expression).GetTypeInfo().Assembly.Location,
typeof(ComponentModel.EditorBrowsableAttribute).GetTypeInfo().Assembly.Location,
typeof(IEnumerable<>).GetTypeInfo().Assembly.Location,
typeof(Text.Encoding).GetTypeInfo().Assembly.Location,
typeof(Threading.Tasks.Task).GetTypeInfo().Assembly.Location,
typeof(IO.MemoryMappedFiles.MemoryMappedFile).GetTypeInfo().Assembly.Location,
typeof(Diagnostics.Debug).GetTypeInfo().Assembly.Location,
typeof(ImmutableArray).GetTypeInfo().Assembly.Location,
typeof(Text.RegularExpressions.Regex).GetTypeInfo().Assembly.Location,
typeof(Threading.Tasks.ParallelLoopResult).GetTypeInfo().Assembly.Location,
};
foreach (string path in paths.Distinct())
{
using (var peStream = File.OpenRead(path))
{
TestChecksumAndAuthenticodeSignature(peStream);
}
}
}