I have a struct like this:
public struct MyStruct
{
public string Name;
public bool Process;
}
And I have a list of myStruct like this:
"123", true
"123", false
"234", true
"345", false
"456", true
"456", false
I want to able to use LINQ to return a list like this:
"123", false
"234", true
"345", false
"456", false
So basically the result I want is a list of distinct names ("123", "234", ...etc) along with the boolean flag and if the names are repeated I need to do an "AND" operation on the flag.
Is there an easy way to do this with one single LINQ statement?
var result = input.GroupBy(e => e.Name)
.Select(gr => new { Name = gr.Key,
All = gr.All(e => e.Process) });
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