Avatar of Thomas PAIK
Thomas PAIK
 asked on

Adding if then structure to LINQ vb.net code

Hi.
How do I add conditional commands (if then structure) to a chain of LINQ vb.net code?

[Sample if then code]
if TextArray.contains("c") then
   TextArrayResult = TextArray.AsEnumerable().Takewhile(Function(x) NOT x.contains("c")).ToArray()
elseif TextArray.contains("d") then
   TextArrayResult = TextArray.AsEnumerable().Takewhile(Function(y) NOT y.contains("d")).ToArray()
else
   TextArrayResult = TextArray
end if

[Test variables with results to the sample code]
1. Inputing TextArray ={"a","b","c","d","e"} gives TextArrayResult = {"a","b"}
2. Inputing TextArray ={"a","d","e"} gives TextArrayResult = {"a"}
3. Inputing TextArray ={"a","b","e"} gives TextArrayResult = {"a","b","e"}

[Desired: an equlivalent 1-line vb.net code preferably in LINQ style]
TextArrayResult = TextArray.AsEnumerable()...
Visual Basic.NET* if statementsLINQ Query

Avatar of undefined
Last Comment
it_saige

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
it_saige

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck