Regarding static var for singleton: I found that static vars are not initialized until the first time you use the class. If you don't use the class, they are never initialized. So your one argument against using a static var is refuted. As another poster pointed out, your code is not thread-safe. In the end, the simplest and best approach is the static var. There was an article about the singleton pattern in C# (in MSDN I think), and it came to exactly the same conclusion.
The only problem I have found with static variables is potential mutual dependencies, which can be resolved using a static contructor (type constructor). On Wed, 5 Jun 2002 14:28:05 -0700, Stefan Holdermans <[EMAIL PROTECTED]> wrote: >But more important: the first approach creates the singleton instance on >demand. The second approach just creates the instance, even if it isn't >needed throughout the life of an AppDomain. Often singetons are >issued 'heavy' objects: recall the in-memory database mentioned earlier in >this thread. You typically don't want these big things created when you >don't really need them. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.
