I have two objects declared as IEnumerable<DateTime>
xVal and IEnumerable<double>
yVal.
Then some where is my program I have:
var xVals = from p in result where p.chemical == "Benzene" select p.SampDate_Name;
var yVals = from p in result where p.chemical == "Benzene" select p.PCL;
Then I am trying to the following assignment:
xVal = xVals as IEnumerable<DateTime>;
yVal = yVals as IEnumerable<double>;
And the above code sets xVal
and yVal
to null.
Could anybody explain what is wrong here? I would very much appreciate the help.
Thanks.
One thing is certain: The input is not null. So xVals and yVals are non-null as debugged by me. I am also able to loop through them to get the content of each. I will try the other suggestions when I get back and post my findings. Thanks a lot folks for your replies.
The problem here was that LINQ is executed lazy, It will be executed when you do either foreach or ToList/ToArray/ToDictionary. The two linq queries in my code were not executed before the assignment was done. Consequently xVal and yVal were set to null. Thanks for all the help.