- private bool check(string str) {
- return str.EndsWith("xxx");
- }
- Predicate < string > predicate = new Predicate < string > (check));
如果逻辑不复杂,可以这样写
- private void OpenMenu(GameObject gob) {
- Predicate < string > predicate = new Predicate < string > (s = >s.StartsWith(gob.name));
- int i = _nameList.FindIndex(predicate);
- }
predicate 这句可以简化一下
- Predicate < string > predicate = s = >s.StartsWith(gob.name);
这样直接放在 list 里边就可以了
- int index = _nameList.FindIndex(s = >s.StartsWith(gob.name));
未找到返回 - 1
来源: http://www.jianshu.com/p/3e3118e1eb87