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[
13 public Point(double x, double y) {
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);
22 public override string ToString() {
23 return string.Format("({0}, {1})", x, y);
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);
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>