Name Employee と Employees という 2 つの異なるクラスがあります。インターフェイス名 IEmployeeService があります。ここには、Get(With Parameter) と Gets() という 2 つのメソッド名が含まれています。このインターフェイスは、別のクラス名 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
    }
}