c# - Cast StringCollection as List<int> -
this question has answer here:
- how convert list<string> list<int>? 7 answers
i have stringcollection object being passed through reportparameter object, , need list<int> instead.
so far, i've tried this
list<int> ids = (parameters != null) ? parameters[parameters.findindex(x => x.name == "ids")].values.cast<int>().tolist() : null; which should check if parameters object null, , if not finds index of ids parameter, , tries cast values list of ints. keep getting cast not valid error. how go converting stringcollection list<int> ?
they string values, can't cast string int. need convert/parse like:
parameters[parameters.findindex(x => x.name == "ids")].values .cast<string>() //so linq applied .select(int.parse) .tolist() you need .cast<string>() can apply linq on stringcollection.
Comments
Post a Comment