gpt4 book ai didi

c# - 方法重载的可选参数

转载 作者:太空宇宙 更新时间:2023-11-03 20:15:33 26 4
gpt4 key购买 nike

我有一个这样的方法:

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
{}

到目前为止一切顺利...但是我需要在 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
{}

问题是现在我遇到了不明确的调用错误...解决该问题的最佳选择是什么(不增加方法数)?

最佳答案

删除重载的默​​认值 (null)。因为您添加了具有默认 null 值的重载,所以编译器根本不知道要使用哪一个。

关于c# - 方法重载的可选参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16967831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com