Static Constructors initialize the static fields/properties of the class/static class. Static Constructors donot allow access modifiers so will work in background with the instructions of initialization of static resources in the class
In this post we exemplify the construction of a class containing static fields
.2018
In this post we exemplify the construction of a class containing static fields
public class Particle<T> where T : new()
{
static T StaticElement { get; set; }
public T Element { get; set; }
public double Density { get; set; }
// ctor
public Particle(double density)
{
Density = density;
}
// static ctor
static Particle()
{
StaticElement = new T();
}
public Particle<T> MuteParticle(Func<T, Particle<T>> muteFunction)
{
return muteFunction(StaticElement);
}
}
.2018