Threading and static methods in C#
Yes, each thread gets its own separate local variable. This function will always return 2 even if called by multiple threads simultaneously.
Yes, that's a correct assessment. x
is a method-local variable, and won't be shared between invocations of MyExtensionMethod
.
Quite simply, yes. A static method only means that the method can be called without an object. The local variables within the method are still local.