且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重载采用具有不同类型的通用列表作为参数的方法

更新时间:2022-11-21 07:58:46

当然可以...使用泛型!

Sure can... using generics!

private static List<allocations> GetAllocationList<T>(List<T> allocations) 
   where T : BasePAllocationClass
{

}

这假设您的分配","PAllocation"和"NPAllocation"都共享一些称为"BasePAllocationClass"的基类.否则,您可以删除"where"约束,并自行检查类型.

This assumes that your "allocations", "PAllocation" and "NPAllocation" all share some base class called "BasePAllocationClass". Otherwise you can remove the "where" constraint and do the type checking yourself.