I have the following line of code:
List<int> _people = code.data.loadScalarDataPoint(code.enums.pathNames.Department, "Department_Staff", RecId).Split('|').Select(int.Parse).ToList();
The static method loadScalarDataPoint returns a string of the selected column for given inputs.
In this instance, it returns a list of pipe delimited integers (e.g. 12|45|88|1543|123) or if the column is NULL it will return an empty string.
Using the linq Select(int.Parse) works if there is a result but without it throws the following error "Input string was not in a correct format"
I know why, as you can't parse an empty string into a int, however is there a way within the single line of code to check for this?
Or do I need to get the result into a string, check if it has contents and if so parse into a list of ints?
new List<string>().Select(int.Parse).ToList()works perfectly fine. Please consider providing actual sample that shows the problem. Possibly Nick Stuart's answer explains the problem (if you in fact have non-empty array)."".Split('|').Select(int.Parse);would work but if the value before .Split is null, there would be an exception. The only time that the reported exception should show is when your string is actually not convertible to an int.var r = "some string". Split(....in addition to actual code you have.