[英]How to find an index of a string within a List in .Net 2.0
我试图获取List中字符串的索引号。 我尝试了以下代码:
List<string> Markets = new List<string>() {"HKG", "TYO", "NSE", "STU", "FRA", "LON", "SIN", "MIL", "TSE", "ASX", "STO", "AEX", "MEX", "NSE", "EPA", "SWX", "CVE", "BRU", "SWX"};
int index = Markets.FindIndex("HKG");
出现以下错误:
'System.Collections.Generic.List.FindIndex(System.Predicate <string>)'的最佳重载方法匹配有一些无效参数参数1:无法从'string'转换为'System.Predicate <string>'
知道如何让编译器喜欢这段代码吗?
PS我使用的是QuantShare的C#,应该是.Net 2.0
使用IndexOf
int index = Markets.IndexOf("HKG");
使用FindIndex:
List<string> Markets = new List<string>() { "HKG", "TYO", "NSE", "STU", "FRA", "LON", "SIN", "MIL", "TSE", "ASX", "STO", "AEX", "MEX", "NSE", "EPA", "SWX", "CVE", "BRU", "SWX" };
var index = Markets.FindIndex(a => a == "HKG");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.