Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oop 转换IList<;界面>;列出<;类别>; 列表结果=新列表(); 结果=oElectionsManager.GetCurrentSelectionsByEID( employeeId.StringToGuid(),planYear)作为列表; 公共类CurrentElectionService:ICurenElection { //在此处实现接口字段 }_Oop_C# 4.0_Interface - Fatal编程技术网

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>;