I have a list of type which contains 5 fields. From this list I wish to retrieve values where it groups IssueType & ID together. So that in the table below the issueType ABC & Id = 2 only appears once in my new list. How do I do this?
I should also point out that IssueType is an enumeration. Not sure if this makes any difference
IssueType Id
ABC 1
ABC 2
ABC 2
ABC 3
XZY 4
XYZ 1
I have tried using the groupby in LINQ.
List<IssueLog> uniqueErrorLog = ErrorLog.GroupBy(err => err.IssueType, err => err.Id).Select(err => err).ToList();
Update
Ok so I have since tried the line below.
var uniqueErrorLog = ErrorLog.GroupBy(iss => new { iss.IssueType, iss.Id });
I then check the output and the grouping seems to have made no difference. Going back to my table example I can still see two ABC's with ID = 2 being output when I only want one.
foreach (var issueType in uniqueErrorLog)
{
foreach(var issue in issueType)
Console.WriteLine(issue.IssueType + "," + issue.Id);
}