Note: the question originally showed a pragma disabling CS0462, not CS0642.
You can only disable warnings, not errors. CS0462 is an error, not a warning, hence you can't disable it. Basically this is a problem in your code that you need to fix rather than ignore. (I'd personally suggest fixing the code rather than suppressing warnings in almost all cases anyway, but at least there's the option for warnings.)
Now that the question has been changed to refer to CS0642, it looks like what had actually happened was that you'd got the wrong number in the pragma. This works fine for me - the warning is disabled:
using System;
class Test
{
static void Main()
{
#pragma warning disable 0642
if (true);
#pragma warning restore 0642
}
}
So basically, when you're trying to disable a warning, make sure you're using the right number.