Just sharing a sample code to remove duplicates from a list using LINQ
public class MyClass
{
public string ID { get; set; }
public string Value { get; set; }
}
List<MyClass> myList = new List<MyClass>();
var xrmOptionSet = new MyClass();
xrmOptionSet.ID = "1";
xrmOptionSet.Value = "100";
var xrmOptionSet1 = new MyClass();
xrmOptionSet1.ID = "2";
xrmOptionSet1.Value = "200";
var xrmOptionSet2 = new MyClass();
xrmOptionSet2.ID = "1";
xrmOptionSet2.Value = "100";
myList.Add(xrmOptionSet);
myList.Add(xrmOptionSet1);
myList.Add(xrmOptionSet2);
// here we are first grouping the result by label and then picking the first item from each group
var myDistinctList = myList.GroupBy(i => i.ID)
.Select(g => g.First()).ToList();
Hope it helps..
Load your programming emulators on the cloud & access it conveniently on virtual desktops with your preferred mobile device (iOS/Android/windows) remotely with CloudDesktopOnline.com. For effective team collaboration use a hosted SharePoint and exchange from Apps4Rent.
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

As it is only two values, would you not rather use a dictionary and check before adding to dictionary?
LikeLike
GREAT!
LikeLike
great
LikeLike
thanks very
LikeLike
Thanks a lot!
LikeLiked by 1 person
Thanks
LikeLiked by 1 person
Works just fine. Thank you very much
LikeLiked by 1 person
Great working fine…
LikeLike
Excellent
LikeLike
Thanks, nothing worked for me until now, great aport
LikeLiked by 1 person
thank you
LikeLike
Thanks!
LikeLike
Thanks, It’s work
LikeLike
This one liner replaced like 20 lines of code for me!!! Thank you!!!
LikeLike
Glad it helped Mike
LikeLike