From the client API I get list of data. I have following code, this is a sample code, just need to create sample list to show client data.
class Program
{
static void Main(string[] args)
{
List<Author> authors = new List<Author>
{
new Author { Id = "100", Status = "Time (02:15 PM)" , Value = "A" , Test = "B" },
new Author { Id = "101", Status = "Time (02:16 PM)" , Value = "A" , Test = "B"},
new Author { Id = "100", Status = "Time (02:10 PM)" , Value = "A" , Test = "B"},
new Author { Id = "100", Status = "Time (11:15 AM)" , Value = "A" , Test = "B"},
new Author { Id = "101", Status = "Time (03:40 PM)" , Value = "A" , Test = "B"},
new Author { Id = "100", Status = "Time (02:15 AM)" , Value = "A" , Test = "B"}
};
var aa = authors.ToList();
}
}
public class Author
{
public string Id { get; set; }
public string Status { get; set; }
public string Value { get; set; }
public string Test { get; set; }
}
Here I need to get distinct Id
with their maximum Status by its time value.
From the output I should need to get this.
- Id =
100
, its maximum Status is :Time (02:15 PM)
- Id =
101
, its maximum Status is :Time (03:40 PM)
How can I do this, its looks something mad, but I need to do this. how can I do this
Updated :
DateTime dt1 = DateTime.Now ;
List<Author> authors = new List<Author>
{
new Author { Id = "100", Test = "A", dateTime = dt1.AddMinutes(-5) },
new Author { Id = "101", Test = "K", dateTime = dt1.AddMinutes(-8) },
new Author { Id = "100", Test = "C", dateTime = dt1.AddMinutes(-6) },
new Author { Id = "100", Test = "D" , dateTime = dt1.AddMinutes(-18)},
new Author { Id = "101", Status = "G" , dateTime = dt1.AddMinutes(-6)},
new Author { Id = "100", Status = "Q" , dateTime = dt1.AddMinutes(-3)}
};
Updated my question, I added
I added another field called datetime
for the ease of the Get max value. Then how can I get maximum datetime
for each Id
Output need there two records data,
Id = "100", Status = "Q" , dateTime = dt1.AddMinutes(-3)
Id = "101", Status = "G" , dateTime = dt1.AddMinutes(-6)