Using LINQ
, I'm trying to select unique Customer
's as Person
objects. I'm using JSON
data in the following example but I'm working with POCO
objects in C#
. In this example, I chose JSON
to keep things simple.
I have the following Customer
list:
[
{
"id": 123,
"name: "John Smith",
"transactionDate": "2019-08-21T10:30",
"amount": 8.50
},
{
"id": 234,
"name: "Jane Doe",
"transactionDate": "2019-08-22T18:21",
"amount": 75.00
},
{
"id": 123,
"name: "John Smith",
"transactionDate": "2019-08-26T10:30",
"amount": 10.00
}
]
I want to get the unique customers as Person
objects and the result, should look like this:
[
{
"id": 123,
"name": "John Smith"
},
{
"id": 234,
"name": "Jane Doe"
}
]
The following should give me the unique ID's.
var uniqueIds = customers.Select(x => x.id).Distinct();
How do I now extract unique Person
's from List<Customer>()
?