What exactly does new object() do in c# [on hold]

  • A+

I have had trouble wrapping my head around this and it seems to have lack luster documentation. For example, this code:

private static readonly Object obj = new Object();

Can someone parse through this code and explain what is happening here. What exactly are the properties of this new object that was created? Why create an object this way?


You create a new oject with the type of Object. In most cases a statement like this is used for locking purpuse, see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/lock-statement for more information.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: