链接组合框和并行数组

时间:2017-04-07 22:25:15

标签: c#

我需要帮助将组合框链接或映射到C#中的并行数组。我有一个课程项目,我需要创建一个显示税后净支付的工资单系统。

我想将具有工资核算所需的所有员工信息的并行数组链接到组合框中选择的选项。我觉得我几乎拥有它,但我不知道如何链接从组合框和我设置的并行数组中选择的选项。

   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;

   namespace ZNSPayrollSystem
   {
       public partial class ZNSPayrollSystem : Form
       {

           public ZNSPayrollSystem()
            {
                InitializeComponent();

                string[] arr = { "001 Peters", "002 Barnes", "003 Harris" };
                cboEmp.DataSource = arr.ToArray();

            }

            private void btnCalc_Click(object sender, EventArgs e)
            {
                //parallel arrays         
                int[] empID = { 001, 002, 003 };
                string[] empName = { "James Peters", "Sarah Barnes", "Candice Harris" };
                double[] hrsWorked = { 40, 40, 40 };
                double[] empWage = { 55.50, 65.50, 75.70 };

                //declarations
                double dblTaxRate = 8.2 / 100;
                double dblNetPay;
                double dblGrossPay;
                double dblTaxWithheld;

                dblGrossPay = hrsWorked[] * empWage[];
                dblTaxWithheld = dblGrossPay * dblTaxRate;
                dblNetPay = dblGrossPay - dblTaxWithheld;

                txtGross.Text = dblGrossPay.ToString();
                txtTax.Text = dblTaxWithheld.ToString();
                txtNetPay.Text = dblNetPay.ToString();

            }
        }
    }

1 个答案:

答案 0 :(得分:2)

使用<div class="footer-links"> <a href="#">Suggestions</a> <a href="#">Help</a> <a href="#">Contact us</a> </div>的{​​{1}}属性:

SelectedIndex

Combobox表示未选择任何内容。您可能希望单独处理此问题以避免出现任何异常。