what is the problem? that program!!!
class PointF
{
public PointF()
{
}
public PointF(float x, float y)
{
m_x = x;
m_y = y;
}
public static float GetLength(PointF pF1, PointF pF2)
{
return
System.Math.Sqrt(System.Math.Pow(pF1.m_x - pF2.m_x, 2) + System.Math.Pow(pF1.m_y - pF2.m_y, 2));// what is the problem!!! }
public static PointF operator +(PointF pF, SizeF sF)
{
return new PointF(pF.m_x + (float)sF.Width, pF.m_y + (float)sF.Height);
}
public static PointF operator +(SizeF sF, PointF pF)
{
return new PointF(pF.m_x + (float)sF.Width, pF.m_y + (float)sF.Height);
}
public static PointF operator -(PointF pF, SizeF sF)
{
return new PointF(pF.m_x - (float)sF.Width, pF.m_y - (float)sF.Height);
}
public static PointF operator -(PointF pF)
{
return new PointF(-pF.m_x, -pF.m_y);
}
public float X
{
get
{
return m_x;
}
set
{
m_x = value;
}
}
public float Y
{
get
{
return m_y;
}
set
{
m_y = value;
}
}
private float m_x, m_y;
}
class PointF
{
public PointF()
{
}
public PointF(float x, float y)
{
m_x = x;
m_y = y;
}
public static float GetLength(PointF pF1, PointF pF2)
{
return
System.Math.Sqrt(System.Math.Pow(pF1.m_x - pF2.m_x, 2) + System.Math.Pow(pF1.m_y - pF2.m_y, 2));// what is the problem!!! }
public static PointF operator +(PointF pF, SizeF sF)
{
return new PointF(pF.m_x + (float)sF.Width, pF.m_y + (float)sF.Height);
}
public static PointF operator +(SizeF sF, PointF pF)
{
return new PointF(pF.m_x + (float)sF.Width, pF.m_y + (float)sF.Height);
}
public static PointF operator -(PointF pF, SizeF sF)
{
return new PointF(pF.m_x - (float)sF.Width, pF.m_y - (float)sF.Height);
}
public static PointF operator -(PointF pF)
{
return new PointF(-pF.m_x, -pF.m_y);
}
public float X
{
get
{
return m_x;
}
set
{
m_x = value;
}
}
public float Y
{
get
{
return m_y;
}
set
{
m_y = value;
}
}
private float m_x, m_y;
}
well what error are you getting?
Basically your method is declared to return float but the Math.Sqrt is a function that returns double....2 different types
So either change the way you are doing calculations or convert it to a float value some how, or declare the signature of the method is a double, not a float
class App
{
public static void Main()
{
Rectangle r = new Rectangle(new Point(100, -30), new Size(30, 30));
RectangleF rF =
new Rectangle(new PointF(60.2, -30), new SizeF(30, 30.2));
//why? dont convert double to float. what must i ?
System.Console.WriteLine(Point.GetLength(p1, p2));
System.Console.WriteLine(PointF.GetLength(pF1, pF2));
}
}
It looks right to me, although I suppose it could be complaining about the return type being a float. Try changing the line to
return (float)System.Math.Sqrt...
Also, it's more efficient to square something by multiplying it by itself. You would need two temporary variables, say dx and dy, and then use dx*dx + dy*dy.
If this doesn't work (and for all future questions), I suggest explaining why you think there is a problem, and what errors the compiler is giving.