如何使 `Func<>` 的一些参数可选?
How to make some parameters of `Func<>` optional?
var extraRules = new List<Func<string, string, string, bool>>
{
// Current letter is alphanumeric
letter => Regex.IsMatch(letter, "[a-zA-Z]"),
}
如何使第二个和第三个字符串可选?
我试过做类似的事情:
private delegate bool Rules(string letter, string nextLetter = null, string nextNextLetter = null);
然后:
var extraRules = new List<Rules>
{
// Current letter is alphanumeric
letter => Regex.IsMatch(letter, "[a-zA-Z]"),
}
但是我得到了Incompatible anonymous function signature
如何使 Func<>
的某些参数可选?
你不能,但你可以使用弃牌:
var extraRules = new List<Func<string, string, string, bool>>
{
// Current letter is alphanumeric
(letter, _, _) => Regex.IsMatch(letter, "[a-zA-Z]"),
};
var extraRules = new List<Func<string, string, string, bool>>
{
// Current letter is alphanumeric
letter => Regex.IsMatch(letter, "[a-zA-Z]"),
}
如何使第二个和第三个字符串可选?
我试过做类似的事情:
private delegate bool Rules(string letter, string nextLetter = null, string nextNextLetter = null);
然后:
var extraRules = new List<Rules>
{
// Current letter is alphanumeric
letter => Regex.IsMatch(letter, "[a-zA-Z]"),
}
但是我得到了Incompatible anonymous function signature
如何使 Func<>
的某些参数可选?
你不能,但你可以使用弃牌:
var extraRules = new List<Func<string, string, string, bool>>
{
// Current letter is alphanumeric
(letter, _, _) => Regex.IsMatch(letter, "[a-zA-Z]"),
};