方法重载的可选参数

Pau*_*aul 1 c# optional-parameters c#-4.0

我有一个这样的方法:

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
{}
Run Code Online (Sandbox Code Playgroud)

到目前为止一切都很好......但是我需要在Where和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
{}
Run Code Online (Sandbox Code Playgroud)

问题是现在我遇到了模糊调用错误...如何解决这个问题的最佳选择(不增加方法计数)?

Zbi*_*iew 5

删除null重载的默认值().因为您使用默认null值添加了重载,编译器根本不知道使用哪一个.