LINQ Help
How can I get the same functionality with LINQ, I tried looking it up but its usage of lambda functions confused me. Should I stick with this type of loops instead of LINQ and where can I learn LINQ, Microsoft's LINQ documentation is too complex for me. If I need to spend more time before I get into LINQ what should I accomplish / know?
12 Replies
this is pretty difficult to do with LINQ
i would not use LINQ for this
Alright, what do you think about rest of the question?
The main part I'm stuck is at learning these concepts.
You mean LINQ and lambdas?
Yes both.
The latter is very simple once you understand they're just functions
is equivalent to
though, i guess one way to do it is
or you can use a name... i don't know which i prefer
yeah the .Zip and .All methods I don't know what are they used for also I am not familiar with lambdas, I will work on it.
.All()
returns true
if the predicate (the lambda passed into it) returns true
for all elements
not all elements result in a true
from the lambda, so the entire .All()
will return false
Best explanation is with foreach i think atleast thats how i learned
Servator
REPL Result: Success
Console Output
Compile: 506.149ms | Execution: 88.701ms | React with ❌ to remove this embed.
I am not the most advanced at C#, but if you want to get better about solving this type of problem I would recommend looking up folds / reduces and maps.
A map you go over all the values in a collection and perform some function on them. A fold you have an accumulator and a function that takes your accumulator and each value and returns a new value
In this case, All is a type of fold that takes a predicate and returns the AND of all the predicates applied to the values
In LINQ, they call a fold the Aggregate function
Where is a filter
And it looks like Select is a type of map
hope this helps