using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
class Person
{public string thename;
private int hasmoney = 1000;public int Hasmoney
{
get { return hasmoney; }
set
{
hasmoney = value;
}
}
private int tomoney;public int Tomoney
{
get { return tomoney; }
set
{
if (this.hasmoney - value > 0)
{
this.hasmoney -= value;
}
else
{
MessageBox.Show("余额不足");
}
}}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Dictionaryhash = new Dictionary ();
// Hashtable hash = new Hashtable();
public Form1()
{
InitializeComponent();
}private void Form1_Load(object sender, EventArgs e)
{
Listarr = new List ();
//ArrayList arr = new ArrayList();
arr.Add("请选择姓名");
arr.Add("张三");
arr.Add("李四");
this.comboBox1.DataSource = arr;
foreach (string inname in arr)
{
Person pe = new Person();
pe.thename = inname;
hash.Add(inname, pe);
// hash.Add(inname,pe);
}}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string selectname = comboBox1.Text;
if (selectname == "请选择姓名")
{
label1.Text = "";
}
else
{
Person pes = hash[selectname];
label1.Text = pes.Hasmoney.ToString();
}}
private void button1_Click(object sender, EventArgs e)
{string selectname = comboBox1.Text;
if (selectname == "请选择姓名")
{
label1.Text = "";
}
else
{
Person pes = hash[selectname] as Person;
pes.Tomoney = int.Parse(this.textBox1.Text);
label1.Text = pes.Hasmoney.ToString();}
}
}
}