如果我有这个属性:
public ListView GetCurrentListView
我可以传递
等参数public ListView GetCurrentListView(bool flag)
答案 0 :(得分:1)
你的第二个例子不再是属性,而是一种方法。
您不能拥有同名的方法和属性。您通常应该做其中一个,但如果您同时需要属性和方法,则需要为每个属性使用不同的名称。
答案 1 :(得分:1)
只有选项是indexer属性,您可以将属性的类型指定为委托:
void Main()
{
var sample = new Sample();
var odd = sample.Numbers(true);
}
class Sample
{
public Func<bool, IEnumerable<int>> Numbers
{
get => b => Enumerable.Range(1, 100).Select(x => b ? x * 2 : x * 2 - 1);
}
}