I have a class ...
class Document
{
public int GroupID { get; set; }
public bool Valid { get; set; }
}
... and a list of items: IEnumerable<Document> documents. At the first stage, which launches an object on an object through this list, these documents were checked, which means: the property Validwill be truefor some objects and falsefor other objects in the list.
Now in the second step I have to do the following:
- If for at least one document in the group of documents (defined by all documents with the same
GroupID) the flag Validis equal false, then set for all documents in the group Valid false.
For this, I have created so far the following code fragment:
var q = from d in documents
group d by d.GroupID;
foreach (var dg in q)
{
if (dg.Any(d => !d.Valid))
{
foreach (var d in dg)
d.Valid = false;
}
}
I believe this does what I want (I have not tested it so far, though), but not very efficiently.
: , Any foreach "- " LINQ, q , ? ( , , .)
!