C# 我能';t将值赋给“t”;“收藏清单”;在我班上

C# 我能';t将值赋给“t”;“收藏清单”;在我班上,c#,list,class,methods,overloading,C#,List,Class,Methods,Overloading,这是我的类,它包含两个列表集合,用于存储从主窗体发送过来的输入。到目前为止,我的类中没有编译错误,但是我不确定它是否正确。它应该做的是接收输入并在调用时显示它 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace EmployeeRoster { public class Employee {

这是我的类,它包含两个列表集合,用于存储从主窗体发送过来的输入。到目前为止,我的类中没有编译错误,但是我不确定它是否正确。它应该做的是接收输入并在调用时显示它

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

    namespace EmployeeRoster
    {

            public class Employee
            {
                List<string> name = new List<string>();
                List<int> iDnumber = new List<int>();


            public void setEmployeeName( List < string> employeenames, string names)
            {
                employeenames.Add(names);
                employeenames = name;
            }

            public List <string> getEmployeeName()
            {
                return name;
            }

            public void setEmployeeNumber( List < int > employeeId, int numbers)
            {
                employeeId.Add(numbers);
                employeeId = iDnumber;
            }


            public List<int> getEmployeeName()
            {
                return iDnumber;
            }
        }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
命名空间EmployeeRoster
{
公营雇员
{
列表名称=新列表();
List iDnumber=新列表();
public void setEmployeeName(列表employeename,字符串名称)
{
添加(姓名);
employeenames=名称;
}
公共列表getEmployeeName()
{
返回名称;
}
public void setEmployeeNumber(列表employeeId,整数)
{
employeeId.Add(数字);
employeeId=iDnumber;
}
公共列表getEmployeeName()
{
返回iDnumber;
}
}
}
我正在尝试为我在上面的类中创建的列表分配名称,但是我正在尝试下面的代码,我收到了两个错误

  • //错误无法将类型“System.Collections.Generic.List”隐式转换为“string”

  • //错误:方法“setEmployeeName”的重载不包含1个参数

  • 向类中发送参数以填充列表的正确方法是什么

        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 EmployeeRoster
        {
            public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Employee chart = new Employee();
                List < Employee > names = new List < Employee > ();
    
    
                text1.Text = names; // Error Cannot implicitly convert type 'System.Collections.Generic.List<EmployeeRoster.Employee>' to 'string'  
    
                chart.setEmployeeName(names); // Error No overload for method 'setEmployeeName' takes 1 arguments   
    
    
            }
        }
    }
    
    使用系统;
    使用System.Collections.Generic;
    使用系统组件模型;
    使用系统数据;
    使用系统图;
    使用System.Linq;
    使用系统文本;
    使用System.Windows.Forms;
    命名空间EmployeeRoster
    {
    公共部分类Form1:Form
    {
    公共表格1()
    {
    初始化组件();
    }
    私有无效按钮1\u单击(对象发送者,事件参数e)
    {
    员工图表=新员工();
    列表<员工>姓名=新列表<员工>();
    text1.Text=names;//错误无法将类型“System.Collections.Generic.List”隐式转换为“string”
    chart.setEmployeeName(名称);//错误方法“setEmployeeName”的重载不包含1个参数
    }
    }
    }
    
    text1.text=Convert.ToString(名称)

    你可以像那样在飞行中转换它


    我认为你不需要把收集的东西交给全班。类可以为您实例化字符串并将其添加到集合中。

    所以我不需要在类中调用重载方法?哦,转换确实起作用了,谢谢,但是这会将用户输入存储在我的类中创建的列表集合中吗