[StructLayout(LayoutKind.Sequential)]
struct POINT {
public int x;
public int y;
public POINT(int x, int y) {
this.x = x;
this.y = y;
}
public Point ToPoint() {
return new Point(x, y);
}
public static POINT FromPoint(Point pt) {
return new POINT(pt.X, pt.Y);
}
public override bool Equals(object obj)
{
// I wish we could use the "as" operator
// and check the type compatibility only
// once here, just like with reference
// types. Maybe in the v2.0 :)
if (!(obj is POINT))
{
return false;
}
POINT point = (POINT)obj;
if (point.x == this.x)
{
return (point.y == this.y);
}
return false;
}
public override int GetHashCode()
{
// this is the Microsoft implementation for the
// System.Drawing.Point's GetHashCode() method.
return (this.x ^ this.y);
}
public override string ToString() {
return string.Format("{{X={0}, Y={1}}}", x, y);
}
}
<StructLayout(LayoutKind.Sequential)> Structure POINT
Public x As Integer
Public y As Integer
Public Sub New(ByVal x As Integer, ByVal y As Integer)
Me.x = x
Me.y = y
End Sub
Public Function ToPoint() As System.Drawing.Point
Return New System.Drawing.Point(x, y)
End Function
Public Shared Function FromPoint(ByVal pt As System.Drawing.Point) As POINT
Return New Point(pt.X, pt.Y)
End Function
Public Overrides Function ToString() As String
Return String.Format("{{X={0}, Y={1}}}", x, y)
End Function
End Structure
None.
Please add some!
Please add some!