When is a static constructor in C# called?

A static constructor is invoked by the first of either of the following conditions:


  • Create an instance of the class.
  • Refer any of the static methods of the class.

Confused ? Read ahead…


Example

class Sample

{

   static Sample()

   {

      Console.WriteLine(“static constructor called”);

   }

   public static void WriteTime()

   {

            Console.WriteLine(“Static method called”);

   }

   public static void Main(string[] args)

   {

      Sample.WriteTime(); // call 1

      Sample aNewSample = new Sample(); // call 2

   }

}

In the above example, call to the static method WriteTime first calls the static contructor of the class Sample and then the static method is called.

In your Console.Window , you will see:

Line1: static constructor called

Line2: Static method called

 

If after this, you create an instance of the class, the static contructor is not called, as it is only invoked once per class at its first reference (mentioned above). So, call 2

Sample aNewSample = new Sample(); // call 2

will not invoke the static constructor.

 

On the other hand, if there was no call 1 (call 1 is commented out), the static contructor will be invoked when the first object of Sample class is created (a little before the object is created).

Office live site goes live

Office Live (still in beta) website http://officelive.microsoft.com/ went live today.


So what does Office live have for me?


Three categories of services:


1. Microsoft Office Live Basic: Easy to use web site design tool (ala Frontpage online), Free domain name and hosting , 5 personalized email accounts(Office live mail), good data storage and data transfer facilities, and best of all web site traffic analysis and reporting tools, with online support. And all this for free, till the beta period.


Web hosting details:


  • Free hosting
  • 30 MB of Web site storage
  • 10 GB of bandwidth
  • No setup or hidden fees
  • Online customer support
  • Daily backup (data retained for 30 days)

    2. Microsoft Office Live Collaboration: Shared sites(remember Sharepoint), on demand company applications (like shared calenders, Employee directory, expenses, jobs, hiring, Customer management, sales and marketing), and 50 MB of disk space, backed by enhanced data protection.

    3. Microsoft Office Live Essentials: Microsoft Office Live Basic + Sharepoint + 50 email accounts + Microsoft project.. — Complete tools to manage your business online… One stop solution for all your needs. (Free domain name and hosting, Easy to use web site design tool (ala Frontpage online).

     

    So lets get started.

  • Application which does not create an entry in Add/Remove Programs

    Do you want your application not in appear in Add/Remove Programs list?


    If yes, ARPSYSTEMCOMPONENT property of the Windows Installer SDK helps.


    Setting this property to 1 prevents the installed application to be displayed in the Add/Remove Programs List.


    More information on this key is available at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/arpsystemcomponent.asp


    On a side note, i fyou want a quick access to Add/Remove Programs List, type appwiz.cpl at your Start > Run prompt.

    Want to work for Microsoft? Send me your resume

    I contract with Microsoft through Volt (www.volt.com) and currently there are lot of contract positions available.


    If you are interested to work with the best brains in the world and love developing challenging products used by millions in the world, send me your resume at vipul_d_patel@hotmail.com . These are strictly contract positions.


    US Citizen, Green card or H1 visa required. My company Volt does not sponsor new H1, but will willingly transfer your existing H1.


    Looking forward to receiving your resumes. Just send me your resume and I will try to find a position bets suited to your skills.


    If you have any questions, feel free to send me an email  and I will reply to you as soon as possible.