C#控制台应用程序(析构函数)

 

 

using System;
namespace ConsoleApp1
{
    class MyPoint
    {
        private int x;
        private int y;
        public int PX { get { return x; } set { x = value; } }
        public int PY { get { return y; } set { y = value; } }

        public MyPoint() { this.x = this.y = 0; }
        public MyPoint(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
        ~MyPoint()
        {
            Console.WriteLine("MyPoint实例资源回收~~");
        }
        public void ShowPoint() {
            Console.WriteLine("x:{0}\ty:{1}", x, y);
        }
        public float Disp()
        {
            return (float)Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var p0 = new MyPoint();
            var p1 = new MyPoint(4, 5);
            Console.WriteLine(p1.Disp());
        }
    }
}

 

额,这个直接写就好了

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632