xxxxxxxxxx
var uniquePersons = persons.GroupBy(p => p.Email)
.Select(grp => grp.First())
.ToArray();
xxxxxxxxxx
if (!IsPostBack) {
GridView1.DataSource = GetProducts()
.GroupBy(o => new { o.Make, o.Model })
.Select(o => o.FirstOrDefault());
GridView1.DataBind();
}
xxxxxxxxxx
// Assuming we have a class called 'Person' with a 'Name' property
class Person
{
public string Name { get; set; }
}
// Sample data
List<Person> people = new List<Person>()
{
new Person() { Name = "John" },
new Person() { Name = "Mary" },
new Person() { Name = "John" },
new Person() { Name = "Michael" },
new Person() { Name = "Mary" }
};
// Use LINQ to get distinct names
List<string> distinctNames = people.Select(p => p.Name).Distinct().ToList();
// Output
foreach (string name in distinctNames)
{
Console.WriteLine(name);
}