c# - Cast StringCollection as List<int> -


this question has answer here:

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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -