[英]Optional Parameters with method overloding
I have a method like that : 我有这样的方法:
public static void Fill<T> (this DropDownList control,
Expression<Func<T, object>> value,
Expression<Func<T, bool>> whereClause = null,
Expression<Func<T, object>> orderClause = null,
string selectedvalue = null) where T : class
{}
So far so good... But I need add List option to Where and Order clause, so I added more 3 new methods: 到目前为止,一切都很好。但是我需要在List和Order子句中添加List选项,所以我添加了3种新方法:
public static void Fill<T> (this DropDownList control,
Expression<Func<T, object>> value,
IList<Expression<Func<T, bool>>> listWhereClause = null,
IList<Expression<Func<T, object>>> listOrderClause = null,
string selectedvalue = null) where T : class
{}
public static void Fill<T> (this DropDownList control,
Expression<Func<T, object>> value,
IList<Expression<Func<T, bool>>> listWhereClause = null,
Expression<Func<T, object>>> orderClause = null,
string selectedvalue = null) where T : class
{}
public static void Fill<T> (this DropDownList control,
Expression<Func<T, object>> value,
Expression<Func<T, bool>>> whereClause = null,
IList<Expression<Func<T, object>>> listOrderClause = null,
string selectedvalue = null) where T : class
{}
The problem is now I got Ambiguous Invocation error... How is the best option to solve that (without increase the method count)? 现在的问题是我得到了模棱两可的调用错误...解决该问题的最佳选择是什么(不增加方法计数)?
Remove default values ( null
) for your overloads. 删除过载的默认值(
null
)。 Because you've added overload with default null
values compiler simply don't know which one to use. 因为您已经使用默认的
null
值添加了重载,所以编译器根本不知道要使用哪个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.