Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (106.29 KB, 20 trang )
Lập trình trên Windows
với Microsoft® .NET
Giảng viên : Hồ Hoàn Kiếm
Overloading Methods
Áp dụng cho các toán tử :
Overloading Methods
public class Point
{
public int m_x;
public int m_y;
public Point (){ }
public Point(int xx,int yy)
{
m_x = xx ;
m_y = yy;
}
public static Point operator + (Point p1,Point p2) {
Point result = new Point();
result.m_x = p1.m_x + p2.m_y;
result.m_y = p1.m_x + p2.m_y;
return result;
}
}
Overloading Methods
static void Main(string[] args)
{
Point objP1 = new Point(1,1);
Point objP2 = new Point(2,2);
Point objResult = new Point();
objResult = objP1 + objP2;