disable broken tests on net_4_0
[mcs.git] / docs / ecma334 / 8.7.8.xml
blobb5a881757525945a35702e1f8a9dcb3aaeb577e3
1 <?xml version="1.0"?>
2 <clause number="8.7.8" title="Instance constructors" informative="true">
3   <paragraph>An instance constructor is a member that implements the actions required to initialize an instance of a class. </paragraph>
4   <paragraph>The example <code_example><![CDATA[
5 using System;  
6 class Point  
7 {  
8    public double x, y;  
9    public Point() {  
10       this.x = 0;  
11       this.y = 0;  
12    }  
13    public Point(double x, double y) {  
14       this.x = x;  
15       this.y = y;  
16    }  
17    public static double Distance(Point a, Point b) {  
18       double xdiff = a.x - b.x;  
19       double ydiff = a.y - b.y;  
20       return Math.Sqrt(xdiff * xdiff + ydiff * ydiff);  
21    }  
22    public override string ToString() {  
23       return string.Format("({0}, {1})", x, y);  
24    }  
25 }  
26 class Test  
27 {  
28    static void Main() {  
29       Point a = new Point();  
30       Point b = new Point(3, 4);  
31       double d = Point.Distance(a, b);  
32       Console.WriteLine("Distance from {0} to {1} is {2}", a, b, d);  
33    }  
34 }  
35 ]]></code_example>shows a Point class that provides two public instance constructors, one of which takes no arguments, while the other takes two <keyword>double</keyword> arguments. </paragraph>
36   <paragraph>If no instance constructor is supplied for a class, then an empty one with no parameters is automatically provided. </paragraph>
37 </clause>