【发布时间】:2013-11-17 22:27:36
【问题描述】:
这是我的类,它包含两个 List 集合,它们将存储从我的主表单发送过来的输入。截至目前,它在我的课程中没有编译错误,但我不确定它是否正确。它应该做的是接收输入并在调用时显示它。
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;
}
}
}
我正在尝试将名称分配给我在上面的班级中创建的列表,但是我正在尝试下面的代码并且收到 2 个错误
// 错误无法将类型“System.Collections.Generic.List”隐式转换为“字符串”
// 方法 'setEmployeeName' 的错误没有重载需要 1 个参数
为了填写我的列表,将参数发送到 Class 的正确方法是什么?
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
}
}
}
【问题讨论】:
标签: c# list class methods overloading