我有两个不同的班级名称员工和员工。我有一个接口名称 IEmployeeService 这里包括两个方法名称 Get(With Parameter) & Gets()。这个接口在另一个类名EmployeeService 中实现。现在我需要从我的员工类调用我的接口方法“Get()”,从我的员工类调用“Gets()”。有人帮我吗?
我的代码是:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
//My first Class
public class Employee
{
public Employee() { }
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public string Address { get; set; }
public double Salary { get; set; }
//This is a method I want to call My IEmployeeService Get Method from here
public Employee Get(int nEmployeeID)
{
//Try to call Interface Get Method
}
}
//My Second Class
public class Employees : CollectionBase
{
public void Add(Employee oItem)
{
List.Add(oItem);
}
public void Remove(Employee oItem)
{
List.Remove(oItem);
}
//This is my another method I want to call My IEmployeeService Gets Method from here
public static Employees Gets()
{
//Try to call Interface Gets Method
}
}
//My Interface
public interface IEmployeeService
{
Employee Get(int nEmployeeID);
Employees Gets();
}
// My Interface implementation Class
public class EmployeeService : IEmployeeService
{
public EmployeeService() { }
#region IEmployeeService Members
public Employee Get(int nEmployeeID)
{
Employee oEmployee = new Employee();
oEmployee.EmployeeID = 1;
oEmployee.EmployeeName = "Mohammed Faruk";
oEmployee.Address = "Comilla, Bangladesh";
oEmployee.Salary = 50000.00;
return oEmployee;
}
public Employees Gets()
{
Employees oEmployees = new Employees();
Employee oEmployee = new Employee();
for (int i = 1; i <= 10; i++)
{
oEmployee = new Employee();
oEmployee.EmployeeID = i;
oEmployee.EmployeeName = i.ToString() + "th Mohammed Faruk";
oEmployee.Address = i.ToString() + "Comilla, Bangladesh";
oEmployee.Salary = 50000.00;
oEmployees.Add(oEmployee);
}
return oEmployees;
}
#endregion
}
}