Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 17 Classesprevious at this levelnext at this level 17.10 Instance constructorsprevious at this levelnext at this level 17.10.6 Optional instance constructor parameters Paragraph 1[Note: The this(...) form of constructor initializer is commonly used in conjunction with overloading to implement optional instance constructor parameters. In the example
class Text  
{  
   public Text(): this(0, 0, null) {}  
   public Text(int x, int y): this(x, y, null) {}  
   public Text(int x, int y, string s) {  
      // Actual constructor implementation  
   }  
}  
the first two instance constructors merely provide the default values for the missing arguments. Both use a this(...) constructor initializer to invoke the third instance constructor, which actually does the work of initializing the new instance. The effect is that of optional constructor parameters:
Text t1 = new Text();          // Same as Text(0, 0, null)  
Text t2 = new Text(5, 10);       // Same as Text(5, 10, null)  
Text t3 = new Text(5, 20, "Hello");  
end note]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS