Если я правильно понял, челевек хочет узнать как рализовать оператор явного преобразования (explicit casting) Вот пример:
| Код | using NUnit.Framework; namespace ExplicitCastingTest { class Program { static void Main(string[] args) { double area = (double)new BoxArea(10, 10); Assert.AreEqual(100, area); } } public struct BoxArea { double widthCore; double heightCore; public BoxArea(double w, double h) { this.widthCore = w; this.heightCore = h; } public double Width { get { return widthCore; } set { widthCore = value; } } public double Height { get { return heightCore; } set { heightCore = value; } } public double Area { get { return Width * Height; } } public static explicit operator double(BoxArea area){ return area.Area; } } }
|
|