【发布时间】:2011-01-31 18:02:06
【问题描述】:
对不起,我没有在 c# 中处理过很多泛型
according to this question,怎么可能做一个generc集合 实现两个接口 我一直在寻找这样的直接方法:当然会出错,而且完全是错误的。
interface IEmployee {void DisplayInfo();}
interface ISalary {void CalculateSalary();}
class Nurse : IEmployee, ISalary
{
//some Implementation
}
class Doctor : IEmployee, ISalary
{
//some Implementation
}
class EntryPoint
{
static void Main(string[] args)
{
System.Collections.Generic .List<T> employees where T: ISalary,IEmployee
=new System.Collections.Generic .List<T>();
}
Nurse oNurse = new Nurse();
Doctor oDoctor = new Doctor();
employees.Add(oNurse);
employees.Add(oDoctor);
}
在阅读了一些之后,我发现也许我必须首先定义一个这样的泛型类:
public class HospitalEmployee<T> where T : IEmployee, ISalary
{
}
不幸的是它不起作用,现在我很困惑,不知道该怎么做,请帮助,谢谢你
【问题讨论】: