29 Replies
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Why do your delegates take parameters, you're discarding them.
By delegates do you mean the Funcs?
Yeah
It told me to write it like that online
Who told you to write it like that?
You can basically think of this code like this
You're not using the parameter x
Now to answer why it fails it's because
(3+1/6) = 0
0 % 6 = 0
Yeah, here the parameter is used
I'm new to lambda that's why
my code is bad
why are you using delegates anyways
because my teacher wanted us to impress him
and we hadnt learnt about them
Well, using lambdas and delegates doesn't make sense tbh
It's redundant
so its not needed?
Yeah, it's not
oh
so when would it be needed?
Lambdas or delegates?
I don't think this is a valid prime number checker? Number 17 is prime but that code says it isn't
unless I'm missing something lol.
Yeah, it won't work, it'll fail on 4 for example
lambdas
(17 + 1) / 6 = 3
which doesn't divide by 6 exactlyyeah
you can think of lambdas as basically inline functions
assuming you're doing an Uni course, your teacher most likely wants you to implement a primality test like the ones at https://en.wikipedia.org/wiki/Primality_test
im in college
They are called "closures", they can access variables in the the outside scope.
In your example, you can see how you access the number parameters
x => (number + 1) / 6;
yeah
In your case, you don't need to do that at all
alright
thanks for the help!