C# .NET Core linq Distinct
public static IEnumerable<TSource> DistinctBy<TSource, TKey>
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}List<Person> distinctPeople = allPeople
.GroupBy(p => new {p.PersonId, p.FavoriteColor} )
.Select(g => g.First())
.ToList();var distinctUsers = allUsers
.GroupBy(x => x.UserId)
.Select(x => x.First())
.ToList();
Also in C#:
- iterate through xpdictionary devexpress
- c# tuple access
- play animation through script unity
- how to turn a string in a char list c#
- font family behind code uwp c#
- c# AllowSynchronousIO to true
- how to allow user import image c#
- month number to text in c#
- how to add an embedded resource in visual studio code
- singleton unity
- same click event diffrenet buttonms c#
- how to route back to url using Request.Headers["Referer"].ToString() in asp.net core
- unity adding component to another gameobject
- No IUserTwoFactorTokenProvider<TUser> named 'Default' is registered.'
- for each line in string c#
- sort datatable c#
- how to convert object in string JSON c#
- JavaScriptSerializer() and convert to base64
- Generate Genealogy view in mvc C# using Google Organizational Chart
- singleton design pattern c# volatile
- c sharp list length
- how to cast list to observablecollection c#
- unity movement on forward
- get enum by index c#