C# lambda表达式应用如何找出元素在list中的索引
1.先写个规则方法
privateboolcheck(stringstr){
returnstr.EndsWith("xxx");
}
2.再写个Predicate
Predicatepredicate=newPredicate (check));
如果逻辑不复杂,可以这样写
privatevoidOpenMenu(GameObjectgob){
Predicatepredicate=newPredicate(s=>s.StartsWith(gob.name));
inti=_nameList.FindIndex(predicate);
}
predicate这句可以简化一下
Predicatepredicate=s=>s.StartsWith(gob.name);
这样直接放在list里边就可以了
intindex=_nameList.FindIndex(s=>s.StartsWith(gob.name));
未找到返回-1
总结
以上所述是小编给大家介绍的C#lambda表达式应用如何找出元素在list中的索引,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短