I was wondering why static variables can't have a run-time initializer. For example this won't compile: void foo(int input) { static x = input; }
But you can do it manually: void bar(int input) { static bool initted; static typeof(input) x; if (!initted) { x = input; initted = true; } } It's quite a bit more ugly. You also have to expand this for every new static variable that you write. I don't know the background of how static variables really work, so is there a good reason why the first function can't work like the one below it?