Looking around the network, I saw this simple template that implements single-threaded single-threaded (in C #).
public sealed class MySingleton { private static readonly MySingleton _instance = new MySingleton(); private string[] _data = new string[10];
I understand that the _instance
member must be declared as static, as it is accessible from the static Instance()
method.
But should other members be declared as static? By definition, singleton exists only once, so members can also exist only once (for one instance), just as static variables exist only once.
Should I declare _data
as static?
- Will there be any functional difference?
- Any difference in performance?
- Any other reasons for preferring static or non-static?
source share