zoukankan      html  css  js  c++  java
  • 接口属性

    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

  • 相关阅读:
    Visual C#常用函数和方法集汇总
    基于窗体的/Cookie 身份验证示例
    ASP.NET状态存储管理九大兵器之六(缓存)
    ASP.NET中TreeView控件使用
    用.net操作word
    Array排序函数
    用C#制作PDF文件全攻略
    TreeView IE Web 控件的使用(很直观)
    windows共享与权限问题(总结)
    RndNum 生成随机字符串,包含数字和小写字母
  • 原文地址:https://www.cnblogs.com/huyong/p/2685684.html
Copyright © 2011-2022 走看看