zoukankan      html  css  js  c++  java
  • c#使用属性封装

    1、使用属性封装方法

    AccessModifer Type PropertyName
    {
    get{...}
    set{...}
    }
    public int {
    get{ return this.X}
    set{this.x=rangeCheckX(value)}
    }

    2、属性对某个字段封装时,命名规则,首字母大写

    private int employeeID;
    public int EmployeeID
    {
    get{return this.EmployeeID;};
    set{this.EmployeeID=value}
    }

    3、接口中定义属性

    interface IScreenPosition
    
    {
    
    int X{get;set;}
    
    int Y{get;set;}
    
    }

    4、实例化同时赋值

    static void DoWork()
            {
                Polygon square = new Polygon();
                Polygon triangle = new Polygon { NumSides = 3 };
                Polygon pentagon = new Polygon { SideLength = 15.5, NumSides = 5 };
    
                Console.WriteLine("Square: number of sides is {0}, length of each side is {1}", 
                    square.NumSides, square.SideLength);
                Console.WriteLine("Triangle: number of sides is {0}, length of each side is {1}", 
                    triangle.NumSides, triangle.SideLength);
                Console.WriteLine("Pentagon: number of sides is {0}, length of each side is {1}", 
                    pentagon.NumSides, pentagon.SideLength);
            }
  • 相关阅读:
    三点求圆心坐标(三角形外心)
    半平面交
    旋转卡壳
    平面最近点对(HDU 1007)
    凸包
    ACM做题随做随思
    最短路径——SPFA算法
    树链剖分原理
    生成树的计数——Matrix-Tree定理
    次小生成树
  • 原文地址:https://www.cnblogs.com/lujianwei/p/2559458.html
Copyright © 2011-2022 走看看