简单的雇员类的实现

(1)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 简单雇员类
{
    class Employee
    {
        public string id;
        public string name;
        public Employee() { }
        public Employee(string name,string id) {
            this.name = name;
            this.id = id;
        
        }
        //用于存储雇员数
        //静态方法只能访问类中的静态成员,非静态方法可以访问类中的包括静态方法在内的所有成员。
        public static int employeeCounter;

        public static int AddEmployee() {
            return ++employeeCounter;
        }

      //派生类
        class MainClass : Employee {
            public static void Main() {

                Console.Write("输入雇员姓名:");
                string name = Console.ReadLine();
                Console.Write("输入雇员的id:");
                string id = Console.ReadLine();
                //建立雇员对象
                Employee e = new Employee(name,id);
                Console.Write("输入雇员数:");
                string n = Console.ReadLine();
                //Int32.Parse(n);转换成32位的有符号整数。employeeCounter是静态,所以可以直接用类调用。
                Employee.employeeCounter = Int32.Parse(n);
                //增加雇员数量
                Employee.AddEmployee();
                //显示新信息
                Console.WriteLine("Name:{0}", e.name);
                Console.WriteLine("ID:{0}",e.id);
                Console.WriteLine("新的雇员数为:{0}",Employee.employeeCounter);


            }
        
        }


    }
}

(2)


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值