Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Employee是一个名称空间,但与类型一样使用_C# - Fatal编程技术网

C# Employee是一个名称空间,但与类型一样使用

C# Employee是一个名称空间,但与类型一样使用,c#,C#,我有一个C#作业,当我运行程序时,我得到一个错误,指出“Employee是一个名称空间,但它的使用方式与第18行中的“public double salary;”类似。问题是我没有发现任何错误。有人能帮我修复此代码吗。下面是我当前的代码。任何帮助都将不胜感激 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; us

我有一个C#作业,当我运行程序时,我得到一个错误,指出“Employee是一个名称空间,但它的使用方式与第18行中的“public double salary;”类似。问题是我没有发现任何错误。有人能帮我修复此代码吗。下面是我当前的代码。任何帮助都将不胜感激

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Employee
{
    struct Employees
    {
        public int Worker_ID;
        public string lastname;
        public string firstname;
        public int phone;
        public double salary;
    }
    public partial class Form1 : Form
    {
        private List<Employees> dataList = new List<Employees>();

        public Form1()
        {
            InitializeComponent();
        }

        private void GetData(ref Employees info)
        {
            try
            {
                info.Worker_ID = int.Parse(employeebox.Text);
                info.lastname = lastnamebox.Text;
                info.firstname = firstnamebox.Text;
                info.phone = int.Parse(phonebox.Text);
                info.salary = double.Parse(salarybox.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }       

        private void savebt_Click(object sender, EventArgs e)
        {
            Employees save = new Employees();
            GetData(ref save);
            dataList.Add(save);

            employeebox.Clear();
            lastnamebox.Clear();
            firstnamebox.Clear();
            phonebox.Clear();
            salarybox.Clear();

            employeebox.Focus();
        }

        private void employeesbt_Click(object sender, EventArgs e)
        {
            string output;
            employeelistbox.Items.Clear();
            foreach (Employees aSave in dataList)
            {
                output = aSave.Worker_ID + " " + aSave.lastname + aSave.firstname + "Salary :" + aSave.salary;
                employeelistbox.Items.Add(output);
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
命名空间雇员
{
结构员工
{
公共国际工作者ID;
公共字符串lastname;
公共字符串名;
公共int电话;
公共双薪;
}
公共部分类Form1:Form
{
私有列表数据列表=新列表();
公共表格1()
{
初始化组件();
}
私有void GetData(参考员工信息)
{
尝试
{
info.Worker\u ID=int.Parse(employeebox.Text);
info.lastname=lastnamebox.Text;
info.firstname=firstnamebox.Text;
info.phone=int.Parse(phonebox.Text);
info.salary=double.Parse(salarybox.Text);
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message);
}
}       
私有void savebt_单击(对象发送方,事件参数e)
{
员工储蓄=新员工();
获取数据(参考保存);
dataList.Add(保存);
employeebox.Clear();
Clear();
firstnamebox.Clear();
Clear();
salarybox.Clear();
employeebox.Focus();
}
私有void employeesbt_单击(对象发送者,事件参数e)
{
字符串输出;
employeelistbox.Items.Clear();
foreach(数据列表中的员工aSave)
{
输出=aSave.Worker\u ID+“”+aSave.lastname+aSave.firstname+“工资:”+aSave.Salary;
employeelistbox.Items.Add(输出);
}
}
}
}

您没有在名称空间
Employee
的末尾加上右括号

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Employee
{
struct Employees
{
    public int Worker_ID;
    public string lastname;
    public string firstname;
    public int phone;
    public double salary;
}
public partial class Form1 : Form
{
    private List<Employees> dataList = new List<Employees>();


    public Form1()
    {
        InitializeComponent();
    }

    private void GetData(ref Employees info)
    {
        try
        {
            info.Worker_ID = int.Parse(employeebox.Text);
            info.lastname = lastnamebox.Text;
            info.firstname = firstnamebox.Text;
            info.phone = int.Parse(phonebox.Text);
            info.salary = double.Parse(salarybox.Text);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }


    }       

    private void savebt_Click(object sender, EventArgs e)
    {
     Employees save = new Employees();
        GetData(ref save);
        dataList.Add(save);

        employeebox.Clear();
        lastnamebox.Clear();
        firstnamebox.Clear();
        phonebox.Clear();
        salarybox.Clear();

        employeebox.Focus();
    }

    private void employeesbt_Click(object sender, EventArgs e)
    {
        string output;
        employeelistbox.Items.Clear();
        foreach (Employees aSave in dataList)
        {
            output = aSave.Worker_ID + " " + aSave.lastname + aSave.firstname + "Salary :" + aSave.salary;
        employeelistbox.Items.Add(output);
        }
    }


}
} // -> 1 Extra Parenthesis required
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
命名空间雇员
{
结构员工
{
公共国际工作者ID;
公共字符串lastname;
公共字符串名;
公共int电话;
公共双薪;
}
公共部分类Form1:Form
{
私有列表数据列表=新列表();
公共表格1()
{
初始化组件();
}
私有void GetData(参考员工信息)
{
尝试
{
info.Worker\u ID=int.Parse(employeebox.Text);
info.lastname=lastnamebox.Text;
info.firstname=firstnamebox.Text;
info.phone=int.Parse(phonebox.Text);
info.salary=double.Parse(salarybox.Text);
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message);
}
}       
私有void savebt_单击(对象发送方,事件参数e)
{
员工储蓄=新员工();
获取数据(参考保存);
dataList.Add(保存);
employeebox.Clear();
Clear();
firstnamebox.Clear();
Clear();
salarybox.Clear();
employeebox.Focus();
}
私有void employeesbt_单击(对象发送者,事件参数e)
{
字符串输出;
employeelistbox.Items.Clear();
foreach(数据列表中的员工aSave)
{
输出=aSave.Worker\u ID+“”+aSave.lastname+aSave.firstname+“工资:”+aSave.Salary;
employeelistbox.Items.Add(输出);
}
}
}
}//->需要一个额外的括号