interface IExampleInterface {
static readonly object _staticMutationLock = new object();
static double _curValueMultiplier = 1d;
public static double CurValueMultiplier {
get {
lock (_staticMutationLock) return _curValueMultiplier;
}
set {
lock (_staticMutationLock) _curValueMultiplier = value;
}
}
int CurValue { get; }
void PrintCurValue() => PrintCurValueDefaultImpl(this);
protected static void PrintCurValueDefaultImpl(IExampleInterface @this) => Console.WriteLine(@this.CurValue * CurValueMultiplier);
}
class ExampleClass : IExampleInterface {
public int CurValue { get; } = 100;
public void PrintCurValue() => IExampleInterface.PrintCurValueDefaultImpl(this); // Deliberately defer to default implementation
}
// ...
class Program {
static void Main() {
IExampleInterface e = new ExampleClass();
IExampleInterface.CurValueMultiplier = 2d; // Static property access
e.PrintCurValue(); // Prints 200
}
}
Code snippet taken from "Complete C# Quick Reference - C# 8".