如何将参数传递给此方法

时间:2017-12-06 14:23:25

标签: c#

这是方法:

getUsersList(ref List<RealBioSDKUser> userList, 
             int groupId = -1, 
             [DateTimeConstant(0), Optional] DateTime fromDate)

当我传递这样的参数时:

List<RealBioSDKUser> tempUserList=new List<RealBioSDKUser>();
BioClient.getUsersList(ref tempUserList,0, "1900-01-01");

显示此错误:

  

像collections.generic.list这样的最佳重载方法匹配。

2 个答案:

答案 0 :(得分:4)

因为"1900-01-01"是字符串,而不是DateTime。改为传递DateTime对象:

BioClient.getUsersList(ref tempUserList,0, new DateTime(1900, 1, 1));

答案 1 :(得分:3)

调用时,提供DateTime(即new DateTime(1900, 1, 1))个实例,而不是String"1900-01-01")一个:

getUsersList(ref List<RealBioSDKUser> userList, 
             int groupId = -1, 
            [DateTimeConstant(0), Optional] DateTime fromDate) // <- DateTime


... 

List<RealBioSDKUser> tempUserList = new List<RealBioSDKUser>();

BioClient.getUsersList(ref tempUserList, 0, new DateTime(1900, 1, 1)); // <- DateTime