Link to home
Start Free TrialLog in
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()...
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial