Blog moved to http://blogs.msdn.com/vipul

Hi,


It has been six months since I joined microsoft. I have moved this blog to a new location. http://blogs.msdn.com/vipul


Please update your bookmarks to the new URL. Link to RSS feed : http://blogs.msdn.com/vipul/rss.xml


 

My Faq on "hashtable lookups for struct types" is published at http://blogs.msdn.com/CSharpFaq

 


Check out


http://blogs.msdn.com/csharpfaq/archive/2006/03/20/556192.aspx 


for a FAQ on Hashtable lookup for value types.

Public readonly string vs. public readonly property

EricGu (Microsoft) has made an excellant post on readonly strings and read-only properties. Check it out


http://blogs.msdn.com/ericgu/archive/2006/03/17/553934.aspx

My articles on "Anonymous types" is up

Check out http://www.developer.com/net/csharp/article.php/3589916 for my article on “Anonymous Types“, This cool new feature coming in C# 3.0 is surely going to go places.


Codeguru also contains the same article at http://www.codeguru.com/csharp/csharp/cs_misc/designtechniques/article.php/c11551/


Next stop, extension methods.

Guidelines on clean up code

Many a times, we use the catch block inside the try catch block for our clean up code.


Something like

try


{


 // Do something


}


catch


{


    // work failed, clean up code here
}


 


Rather than the above approach of using the catch block, it would be nicer to use the finally block, something like


 


bool workSuccessful = false;


try


{


   // do some work


   workSuccessful = true;


}


finally


{


  if(!workSuccessfull)


  {


    // cleanup code here.


  }


}


 


There is elegance in the latter method and I would certainly recommend that approach, if you cannot use “using“. See below for details.


 


PS: Use this approach only if better alternatives are not available. One of the automatic cleanup approaches available with C# is the using construct.


Something like,


using (TextReader tr = new StreamReader(“FileName”))


{


  // do my work here.


}


 


The “using” construct automatically clean up the unmanaged resource (TextReader) once the block has completed execution.


In the event that you cannot use “using“, the try-finally approach would be the best way.


 

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).

Sql Server 2005 blocking quiz

Check out http://blogs.msdn.com/psheill/archive/2006/02/20/535614.aspx for a fantastic quiz on SQL Server 2005 blocking and verify if you have got your fundamentals right.


Good job, psheill.

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.

    Visual Studio Service Pack WebSite

    Visual Studio.NET Service Packs are due this year, but their site is up already (The site clearly mentions it is still in process)


    http://msdn.microsoft.com/vstudio/support/servicing/default.aspx


  • Visual Studio 2003 Service Pack 1 ships Q2, 2006
  • Visual Studio 2005 Service Pack 1 ships Q3, 2006
  • Next Page »