- 1

SoloLearn Code Challenges

That's a post for the Code Challenges against other SoloLearn user. When you don't understand why you answer was wrong in one Challenge or how the answer was right just write the Challenge question bellow in the comments. ^^

11th Jun 2022, 4:04 PM
Felix Alcor
Felix Alcor - avatar
7 odpowiedzi
+ 2
If you run it like this: int[] arr = {10, 15, 16}; var x = arr.FirstOrDefault(z => z.Equals(14)); Console.WriteLine(arr.FirstOrDefault()); Console.WriteLine(x); Console.WriteLine(x + 15); You will see that z = 10 (first value in the array). 10.Equals(14) = 0, so x = 0. And 0 + 15 will be 15.
11th Jun 2022, 5:36 PM
Paul
Paul - avatar
+ 2
No i think z.Equals(14) will produce a boolean, so 1 if it is true.
11th Jun 2022, 5:47 PM
Paul
Paul - avatar
+ 2
I was wrong, x is 14 if 14 is in the array, otherwise it is 0. somebody else asked the same question earlier on sololearn, i found it with google: https://www.sololearn.com/Discuss/2129959/can-anyone-explain-this-bit-of-code-i-don-t-really-get-the-expression-assigned-to-x
11th Jun 2022, 6:08 PM
Paul
Paul - avatar
+ 1
Well I will Just start then I don't understand why the answer is 15, I memorized it but I don't know why. C# Code Challenge What's the output of this Code: Int[] arr = {10, 15, 16}; var x = arr.FirstOrDefault(z => z.Equals(14)); Console.WriteLine(x + 15);
11th Jun 2022, 4:15 PM
Felix Alcor
Felix Alcor - avatar
+ 1
I See so does that mean than that if the first value was 14. x would be 14?
11th Jun 2022, 5:44 PM
Felix Alcor
Felix Alcor - avatar
+ 1
I just tried it and when the First value of arr is 14 then x is also 14.
11th Jun 2022, 5:56 PM
Felix Alcor
Felix Alcor - avatar
+ 1
Thanks now I don't Just have the self Test but also the theory knowleght. ^^
11th Jun 2022, 6:32 PM
Felix Alcor
Felix Alcor - avatar