I have list of class of type
public class MyClass
{
public SomeOtherClass classObj;
public string BillId;
}
public List<MyClass> myClassObject;
Sample Values:
BillId = "123",classObj = {},
BillId = "999",classObj = {},
BillId = "777",classObj = {},
BillId = "123",classObj = {}
So in above example, we have duplicate values for BillId
. I would like to remove all the duplicate values (Not Distinct) so the result would contain only 999
& 777
value.
One way to achieve this to
BillId
BillId
in another variableBillId
Is there any straightforward way to achieve this?
Array. filter() removes all duplicate objects by checking if the previously mapped id-array includes the current id ( {id} destructs the object into only its id). To only filter out actual duplicates, it is using Array.
I think this would work:
var result = myClassObject.GroupBy(x => x.BillId)
.Where(x => x.Count() == 1)
.Select(x => x.First());
Fiddle here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With