Constructor (object-oriented programming): Difference between revisions

Content deleted Content added
C# static constructor: Introduced cctor term in the context of class constructors
Line 180:
==== C# static constructor ====
 
In [[C Sharp (programming language)|C#]], a '''static constructor''' is a static data initializer. Static constructors alloware complexalso staticcalled variable'''class initializationconstructors'''. Since the actual method generated has the name '''.cctor''' they are often also called "cctors".<ref>[{{cite web|url=http://msdn.microsoftericlippert.com/en-us2013/library02/06/static-constructors-part-one/k9x6w0hc%28VS.80%29.aspx Static|title=Fabulous ConstructorAdventures in C#Coding on|publisher=Eric MSDN]Lippert |date=2013-02-06|accessdate=2014-04-05}}</ref>
 
Static constructors allow complex static variable initialization.<ref>[http://msdn.microsoft.com/en-us/library/k9x6w0hc%28VS.80%29.aspx Static Constructor in C# on MSDN]</ref>
Static constructors are called implicitly when the class is first accessed. Any call to a class (static or constructor call), triggers the static constructor execution.
Static constructors are [[thread]] safe and implement a [[singleton pattern]]. When used in a [[generic programming]] class, static constructors are called at every new generic instantiation one per type. Static variables are instantiated as well.