用C#编写

2024-12-19 23:55:53
推荐回答(1个)
回答1:

1)员工类Employee public class Employee{ //默认的构造函数 public Employee(){ } //带参数的构造函数 pubic Employee(string name, int employeeId) { Name = name; Id = employeeId; } public string Name{get;set;} public int Id{get;set;}}class Program{ //程序入口 static void Main(string[] args) { //用默认的构造函数实例化 Employee e1 = new Employee(); e1.Name = "张三"; e1.Id = 1; Console.WriteLine("员工姓名:{0}, 员工编号", e1.Name, e1.Id); //用带参数构造函数实例化 Employee e2 = new Employee("王五", 2); Console.WriteLine("员工姓名:{0}, 员工编号", e2.Name, e2.Id); }}2)带静态方法的类 public class Helper{ public static void Show(byte value) { Console.WriteLine("二进制:" + Convert.ToString(value, 2)); Console.WriteLine("八进制:" + Convert.ToString(value, 8)); Console.WriteLine("十六进制:" + Convert.ToString(value, 16)); }}3)平面上的点类Point public class Point{ protected float x, y; public Point( float x, float y) { this.x = x; this.y = y; } public float X { get{ return this.x;} set{ this.x = value;} } public float Y { get{ return this.y;} set{ this.y = value;} }}4)圆类Circle public class Circle : Point{ protected float r; public Cricle(float x, float y, float r) :base(x, y) { this.r = r; } public float Radius { get{ return this.r;} set{ this.r = value;} } public double GetArea() { return r * r * Math.PI; } }