I am trying to get the index number of a string within a List. I tried the following code:
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");
The following errors came up:
The best overloaded method match for 'System.Collections.Generic.List.FindIndex(System.Predicate<string>)' has some invalid arguments Argument 1: cannot convert from 'string' to 'System.Predicate<string>'
Any idea how to get the compiler to like this code?
P.S. I am using QuantShare's C# which is supposed to be .Net 2.0
use IndexOf
int index = Markets.IndexOf("HKG");
Since it's a predicate, you should plug in a lambda function.
FindIndex(x => x == "HKG")
See: http://www.dotnetperls.com/lambda
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With