Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Why this line throws an error?

Practicing interview questions. Why does the second line throws an error? Is it because an explicit conversation is needed? I read about ValueTypes but still don't understand why it errors out..


IEnumerable<object> objects = new List<string>();
IEnumerable<ValueType> v =  objects; //*** error here.
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

I tried casting but I did it wrong. These are the options they gave me (interviewer let me take the questions with me)

Their question was "why is there an error when compiling the code". Looking at your explanation...it's the last one...explicit conversion is needed...correct?

User generated image
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Andy