我有以下函數用於搜索文本匹配的類屬性值,如果它們中的任何一個匹配,則返回true。如何修改lambda語句以從列表索引位置開始並返回該位置
private static List<Func<Type, string>> _properties;
private static Type _itemType;
public static bool Match(string searchTerm)
{
bool match = _properties.Select(prop => prop(_itemType)).Any(value => value != null && value.ToLower().Contains(searchTerm.ToLower()));
return match;
}
_properties列表按照DataGrid列上的綁定屬性的順序排列。 _itemType是類的類型。
我想要做的是,繼續搜索文本,但是,另外改變它,以便它將從列表中的特定屬性的索引處開始並返回,第一個屬性的索引匹配它爲或爲null。
功能的開始看起來像這樣:
public static int Match(int start_index, string searchTerm)
能使用找出最好的方式做到這一點一些幫助。
理解這個權利,你想提供一個'out int'來填充第一個匹配的偏移量? –
是的,這是正確的 – Hank