The static class PointExtensions. | Lecture 5 - slide 28 : 29 Program 3 |
using System; public static class PointExtensions{ public static double DistanceTo(this Point p1, Point p2){ return Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y)); } } | The class must be static. The method must be static, and the first parameter becomes the receiver of the message (the target of the instance method). Notice the this modifier! |