• 接口属性


    interface IEmployee
    {
        string Name
        {
            get;
            set;
        }

        int Counter
        {
            get;
        }
    }

    public class Employee : IEmployee
    {
        public static int numberOfEmployees;

        private string name;
        public string Name  // read-write instance property
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        private int counter;
        public int Counter  // read-only instance property
        {
            get
            {
                return counter;
            }
        }

        public Employee()  // constructor
        {
            counter = ++counter + numberOfEmployees;
        }
    }

    class TestEmployee
    {
        static void Main()
        {
            System.Console.Write("Enter number of employees: ");
            Employee.numberOfEmployees = int.Parse(System.Console.ReadLine());

            Employee e1 = new Employee();
            System.Console.Write("Enter the name of the new employee: ");
            e1.Name = System.Console.ReadLine();

            System.Console.WriteLine("The employee information:");
            System.Console.WriteLine("Employee number: {0}", e1.Counter);
            System.Console.WriteLine("Employee name: {0}", e1.Name);
            System.Console.ReadLine();
        }
    }

    输入:

    210
    Hazem Abolrous
     
    输出:

    Enter number of employees: 210

    Enter the name of the new employee: Hazem Abolrous

    The employee information:

    Employee number: 211

    Employee name: Hazem Abolrous

  • 相关阅读:
    VMwareTools安装笔记
    Oracle常用命令(持续更新)
    window常用命令(持续更新)
    Oracle 中 sys和system帐号的区别
    决策树——排序算法的理论下界
    插入、选择、冒泡、梳排序性能比较
    插入、选择、冒泡排序的综述
    绝知此事要躬行之——插入排序
    Tree 和ls 的使用
    用户目录
  • 原文地址:https://www.cnblogs.com/huyong/p/2685684.html
Copyright © 2020-2023  润新知