C#中简单的this与get的用法(string,decimal)

本文详细介绍了使用C#编程语言创建面向对象的Employee类,并通过实例展示了如何实现员工信息的存储、访问及计算薪资的流程。

 

ContractedBlock.gifExpandedBlockStart.gif代码
namespace First
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Employee E1
= new Employee("xiaohong","you");
E1.Salary
=4.2m;
E1.printEmployee();
this.Close();
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(
"Hi");
this.Close();
}
}
class Employee
{
private string name;
private string alias;
private decimal salary;
public Employee(string name, string alias)
{
this.name = name;
this.alias = alias;
}
public decimal Salary
{
get
{
return salary;
}
set
{
salary
= value;
}
}

public void printEmployee()
{
MessageBox.Show(
"Name:" + name +"\n"+ "Alias:" + alias +"\n"+ "num:" + salary);
// MessageBox.Show( Employee.SalcTax(this));

}
}
}

 

ContractedBlock.gifExpandedBlockStart.gif代码
namespace First
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Employee E1
= new Employee("xiaohong","you");
E1.Salary
=1.10m;
E1.printEmployee();
this.Close();
}
}
class Employee
{
private string name;
private string alias;
private decimal salary;
public Employee(string e, string s)
{
this.name = e;
this.alias = s;
}
public decimal Salary
{
get
{
return salary;
}
set
{
salary
= value;
}
}
public static decimal SalcTax(Employee E)
{
return 3* E.Salary;
}
public void printEmployee()
{
MessageBox.Show(
"Name:" + name + "\n" + "Alias:" + alias + "\n" + "Salary" + Employee.SalcTax(this));
// MessageBox.Show( Employee.SalcTax(this));

}
}
}

 

 

 

转载于:https://www.cnblogs.com/xiaolongone/archive/2010/03/16/1687611.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值