C# 4.0 : Add a Static Constructor and Initialization

10/9/2010 3:55:07 PM
Static fields can be initialized in two ways. One way is with a static constructor, which is similar to a standard constructor, but with no accessibility modifier or arguments:
public class Vertex3d
private static int _numInstances;
static Vertex3d()
_numInstances = 0;

However, because of performance reasons, it is preferable to initialize static fields inline whenever possible, as shown here:

public class Vertex3d
private static int _numInstances = 0;
Top 10
SQL Server System and Database Administration : System Databases
A Complete Instruction For Your PC Kit And How To Buy (Part 3) - Samsung 300E5A-A01
Mobile Phone Game Programming : Using Sprite Animation - Achieving Smooth Animation with the GameCanvas Class
A Slice of Apple: Mac Tips & Tricks
Ipad Lion (Part 1) - Lion paving the way for mountain lion's destiny
SQL Server 2008 : Using @@IDENTITY and NEWID Functions in DML Statements
Algorithms for Compiler Design: IMPLEMENTATION in Bottom-up Parsing
Microsoft SQL Server 2008 R2 : Using FILESTREAM Storage (part 1) - Enabling FILESTREAM Storage
Shoot, Edit and Share From Your Iphone (Part 1)
Android Security : Broadcasts
Most View
What is “LulzEnd”?
Freeware: Ubuntu, Serif WebPlus, Sony Vegas Movies
Windows Phone 7 Development : Handling Device Exceptions
Access media remotely : Step-by-step access your media remotely (part 2)
Windows 7 : Using the Windows Backup Program
Programming with DirectX : Shading and Surfaces - Implementing Texture Mapping (part 1) - 2D Texture Mapping Demo
Algorithms for Compiler Design: THE MACHINE MODEL
“TU ME” …vs Skype and Whatsapp.
Manage iOS with iCloud (Part 2)
Ipad Lion (Part 3) - Other possible features
Sign Language Technology (Part 2) - Why Was Sign Abandoned?
Sharepoint 2010 : Outlining Common Extranet Scenarios and Topologies
Buyer’s Guide - Inkjet printers (Part 2) - Epson WorkForce 545 All-In-One-Printer, Epson WorkForce 845 All-In-One-Printer, HP Officejet Pro 8100 ePrinter, Kodak Office Hero 6.1 All-In-One Printer
Building Android Apps: Web Storage
Facebook vs Google+
Silverlight Recipes : Networking and Web Service Integration - Exchanging Data between Silverlight Applications
Troubleshooting Guide - Internet Connection Problems
SQL Server 2008 : Explaining XML - XML Schema
Designing and Configuring Unified Messaging in Exchange Server 2010 : Unified Messaging Installation (part 1)
Java EE 6 : Servlet Development and Deployment - Request forwarding and response redirection