Hi all this is my first post in this forum, im very new to C#, although I have done a little C++ in the past im still trying to find my feet. So I am just going through a bunch of online tutorials to try & get my head round it. One of these is Microsofts.
In the section Classes\Instance constructors I found the following code:
(The actual page is -
*****************************************************
using System;
class Point
{
public double x, y;
public Point() {
this.x = 0;
this.y = 0;
}
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public static double Distance(Point a, Point b) {
double xdiff = a.x – b.x;
double ydiff = a.y – b.y;
return Math.Sqrt(xdiff * xdiff + ydiff * ydiff);
}
public override string ToString() {
return string.Format("({0}, {1})", x, y);
}
}
class Test
{
static void Main() {
Point a = new Point();
Point b = new Point(3, 4);
double d = Point.Distance(a, b);
Console.WriteLine("Distance from {0} to {1} is {2}", a, b, d);
}
}
************************************************************
I have a very simple question, how is it you can declare two classes of the same name as in this example? Im refering to the two public Point classes, one has no parameters and the other has two parameters. I have also seen this elsewhere and i am very confused!
Thanks
p.s. when i create a thread what are the tags to highlight code?
In the section Classes\Instance constructors I found the following code:
(The actual page is -
*****************************************************
using System;
class Point
{
public double x, y;
public Point() {
this.x = 0;
this.y = 0;
}
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public static double Distance(Point a, Point b) {
double xdiff = a.x – b.x;
double ydiff = a.y – b.y;
return Math.Sqrt(xdiff * xdiff + ydiff * ydiff);
}
public override string ToString() {
return string.Format("({0}, {1})", x, y);
}
}
class Test
{
static void Main() {
Point a = new Point();
Point b = new Point(3, 4);
double d = Point.Distance(a, b);
Console.WriteLine("Distance from {0} to {1} is {2}", a, b, d);
}
}
************************************************************
I have a very simple question, how is it you can declare two classes of the same name as in this example? Im refering to the two public Point classes, one has no parameters and the other has two parameters. I have also seen this elsewhere and i am very confused!
Thanks
p.s. when i create a thread what are the tags to highlight code?