MCQs > IT & Programming > C# > The following program is expected to run, and after 500 ms write 'OK' and exit, but fails to do that. How would you fix this? class Test { int foo; static void Main() { var test = new Test(); new Thread(delegate() { Thread.Sleep(500); test.foo = 255; }).Start(); while (test.foo != 255) ; Console.WriteLine('OK'); } }

C# MCQs

The following program is expected to run, and after 500 ms write "OK" and exit, but fails to do that. How would you fix this? class Test { int foo; static void Main() { var test = new Test(); new Thread(delegate() { Thread.Sleep(500); test.foo = 255; }).Start(); while (test.foo != 255) ; Console.WriteLine("OK"); } }

Answer

Correct Answer: Make foo volatile

Explanation:

Note: This Question is unanswered, help us to find answer for this one

C# Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

C# Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it