troubleshooting Question

Adding if then structure to LINQ code

Avatar of Thomas PAIK
Thomas PAIK asked on
Visual Basic.NET* if statementsLINQ Query
1 Comment1 Solution11 ViewsLast Modified:
How do I add conditional commands (if then structure) to a chain of LINQ 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()
   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 code preferably in LINQ style]
TextArrayResult = TextArray.AsEnumerable()...
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros