A friend was given an assignment at the interview, to explain why the code does not work, in general, he did not pass the interview, but we decided to sit on the test task together, didn’t come to any sensible result on our own, maybe you can tell what’s wrong here. The code is compiled, but is not executed.

class MiddleTask { delegate bool Comparer(int a, int b); delegate void Executer(string message); static int MaxValue(int a, int b, Comparer comp) { return comp(a, b) ? a : b; } static void TExecute(int cicle, Executer method) { var inc = 0; while (inc <--cicle) { method("Execute method-comparer"); } } static void Main(string[] args) { Trace.WriteLine("Entry point..."); TExecute(3, (dy) => { var targetRangeModel = new { range = 0, comparerPrefix = "Compare result:" }; var index = 0; var target = 20; while (index-- > targetRangeModel.range && target-- > index) { Trace.WriteLine(targetRangeModel.comparerPrefix + ">>>" + MaxValue(22, 15, (x, y) => { return (x > y) ? true : false; } ) ); } }); 

Closed due to the fact that off-topic participants Kromster , Dmitriy Simushev , Vadim Ovchinnikov , VladD , user194374 19 Jan '17 at 11:17 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, Dmitriy Simushev, Vadim Ovchinnikov, VladD, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 6
    What is "code not working"? Does not compile, does not start, returns an error, returns an incorrect result (and which one is then correct)? Questions asking for help with debugging (“why does this code not work?”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question. Questions without an explicit description of the problem are useless for other visitors. - Kromster

1 answer 1

You never run a cycle

 while (index-- > targetRangeModel.range && target-- > index) 

Because condition index-- > targetRangeModel.range will always be false

  • That's the same) Got on -> && <- I think what kind of magic operators are. - QuaternioNoir