Dejan, Afraid not. Otherwise you would have static initializers going off all over the place. The following reference in the SDK documentation has more detail:
ms-help://MS.VSCC/MS.MSDNVS/csref/html/vclrfstaticconstructors.htm The thing about static constructors is that they have a limited scope for use because of this lack of control, but in reality its not a problem since developers can always declare an initialization method to perform the init, and an interesting approach is to make that method a no-op that is just sufficient to kick of the static constructor. public class StaticAPI { static StaticAPI() { Console.WriteLine("StaticAPI::StaticAPI()"); } public static void Initialize() { Console.WriteLine("StaticAPI::Initialize()"); } public static void APICall() { Console.WriteLine("StaticAPI::APICall()"); } } So the possible execution sequence becomes: StaticAPI::StaticAPI() StaticAPI::Initialize() StaticAPI::APICall() -or- StaticAPI::StaticAPI() StaticAPI::APICall() Personally I don't like initializer methods if I can possibly avoid them, but it does allow you to make the code a little more predictable at certain points in execution if you know that all the initialization has been done up front. ---------------------------------------- - Mitch Denny - [EMAIL PROTECTED] - +61 (414) 610-141 - -----Original Message----- From: The DOTNET list will be retired 7/1/02 [mailto:[EMAIL PROTECTED]] On Behalf Of Dejan Jelovic Sent: Wednesday, 5 June 2002 22:37 To: [EMAIL PROTECTED] Subject: [DOTNET] calling static constructors Is there a way to ensure that a static constructor is called for a class without creating an instance or calling some other static function? Thanks, Dejan (www.jelovic.com) You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.