【发布时间】:2014-01-27 03:32:45
【问题描述】:
我有一种方法,它采用一个动态类型(可能不相关)的参数和多个类型的多个可选参数。有没有办法指定你传递的参数?
使用这段代码,我得到了编译器错误(如下),我希望不必为可选参数编写重载或重写具有多个顺序的函数。
- 错误 2 参数 3:无法从 'string' 转换为 'bool'
- 错误 1 最佳重载方法匹配 Index(int, bool, bool, string)' 有一些无效参数
代码:
public void DoSomeWork()
{
Index<int>(Id, false,"test"); //compiler error
}
private void Index<T>(T o, bool flush = false, bool userDispose = true, string starter = "stop")
{
}
【问题讨论】:
标签: c# .net optional-parameters