I am a C / C ++ programmer recently working in C # and I am trying to do some fancy initialization things that I came across with some problems.
The best and easiest example that I can come up with is that I want to create an "Eager" Singleton - one that is created immediately when the program starts, but without me you need to go to the main function of the program and say "Singleton.Instance () "like the first. I read a static instance, and it looks like it should be called or created before creating the static object, so I tried to create a static variable that instantiated the object, but that didn't work. (I could not find documentation on when static variables are created or initialized).
Any pointers?
Thanks!
Edit: after some additional research, I think I can accomplish what I'm looking for with one block of code using reflection
source share