• C#面对对象(用Dictionary字典实现银行取钱系统)


    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
        {
            Dictionary hash = new Dictionary();
            // Hashtable hash = new Hashtable();
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                List arr = 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();

                }


            }
        }
    }
     

     

  • 相关阅读:
    阿里云99元服务器2核2G3M带宽_4年396元_新老用户均可
    Guava Cache 原理分析与最佳实践
    STM32物联网项目-GPRS模块介绍
    微信实现消息自动回复、群发等功能,还可限时免费使用!
    Linux下找出吃内存的方法
    Kubernetes亲和性学习笔记
    Linux中getopt函数、optind等变量使用详解
    (完美方案)解决mfc140u.dll文件丢失问题,快速且有效的修复
    Docker 常用命令总结
    全排列问题
  • 原文地址:https://blog.csdn.net/Mr_wangzu/article/details/133817718