Oop 转换IList<;界面>;列出<;类别>; 列表结果=新列表(); 结果=oElectionsManager.GetCurrentSelectionsByEID( employeeId.StringToGuid(),planYear)作为列表; 公共类CurrentElectionService:ICurenElection { //在此处实现接口字段 }
方法Oop 转换IList<;界面>;列出<;类别>; 列表结果=新列表(); 结果=oElectionsManager.GetCurrentSelectionsByEID( employeeId.StringToGuid(),planYear)作为列表; 公共类CurrentElectionService:ICurenElection { //在此处实现接口字段 },oop,c#-4.0,interface,Oop,C# 4.0,Interface,方法GetCurrentElectionsByEId返回我IList,我想将接口强制转换为类CurrentElectionService,但它返回null。请帮忙 为什么不使用LINQ来执行演员阵容 List<CurrentElectionService> result = new List<CurrentElectionService>(); result = oElectionsManager.GetCurrentElectionsByEId( emp
GetCurrentElectionsByEId
返回我IList
,我想将接口强制转换为类CurrentElectionService
,但它返回null。请帮忙 为什么不使用LINQ来执行演员阵容
List<CurrentElectionService> result = new List<CurrentElectionService>();
result = oElectionsManager.GetCurrentElectionsByEId(
employeeId.StringToGuid(), planYear) as List<CurrentElectionService>;
Public class CurrentElectionService : ICurentElection
{
// Implement Interface fields here
}
List result=oElectionsManager.GetCurrentElectionsByEId(
employeeId.StringToGuid(),planYear).Cast().ToList();
我希望这会有所帮助。您需要找出实际返回值的类型。如果实际对象不是要将其强制转换到的类型,则
as
keywort始终返回null
根据您给出的定义,您还可以尝试以下方法:
List<CurrentElectionService> result = oElectionsManager.GetCurrentElectionsByEId(
employeeId.StringToGuid(), planYear).Cast<CurrentElectionService>().ToList();
列表结果;
结果=oElectionsManager.GetCurrentSelectionsByEID(
employeeId.StringToGuid(),planYear)作为列表;
如果使用“as”关键字进行转换,如果结果不是该类型,则会得到null。请更详细地描述GetCurrentSelectionsByEID的功能。您真的需要列表吗?为什么不使用该方法提供的IList
?你缺少哪些方法?请注意,Enumerable
扩展方法可以为您提供List
所能提供的一切。我需要为WCF服务公开此方法,我认为我们不能在WCF中公开ILIST
List<ICurentElection> result;
result = oElectionsManager.GetCurrentElectionsByEId(
employeeId.StringToGuid(), planYear) as List<ICurentElection>;