Search code examples
c#staticthread-safetypropertiesautomatic-properties

Are C# auto-implemented static properties thread-safe?


I would like to know if C# automatically implemented properties, like public static T Prop { get; set; }, are thread-safe or not. Thanks!


Solution

  • It appears not. This is the decompilation with Reflector:

    private static string Test
    {
        [CompilerGenerated]
        get
        {
            return <Test>k__BackingField;
        }
        [CompilerGenerated]
        set
        {
            <Test>k__BackingField = value;
        }
    }