Avatar of deleyd
deleyd
Flag for United States of America asked on

Can this LINQ+foreach loop be converted to LINQ?

Can the following be refactored to a single LINQ statement?
var result = 
    from a in listA
    from b in listA
    where a != b
    select new C(a,b);

var newResultList = new List<C>();

foreach (C c in result)
{
    if (c.Sometest()) { newResultList.Add(c); }
}

Open in new window

I'm looking for a way in a LINQ statement to create a new instance of a class C so I can then test by calling c.Sometest() which returns a Boolean, and that determines if the element gets filtered out or left in the collection.

Is that possible?
* LINQProgramming

Avatar of undefined
Last Comment
deleyd

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Juan Carlos

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
deleyd

ASKER
Perfect thank you!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23