Disable/suppress warning CS0649 in C# for a specific field of class

You could use #pragma warning to disable and then re-enable particular warnings:

public class MyClass
{
    #pragma warning disable 0649

    // field declarations for which to disable warning
    private object foo;

    #pragma warning restore 0649

    // rest of class
}

Refer to Suppressing “is never used” and “is never assigned to” warnings in C# for an expanded answer.


I believe it's worth noting the warning can also be suppressed by using inline initialization. This clutters your code much less.

public class MyClass
{
    // field declarations for which to disable warning
    private object foo = null;

    // rest of class
}

//disable warning here
#pragma warning disable 0649

 //foo field declaration

//restore warning to previous state after
#pragma warning restore 0649