This seems really simple, but I can't figure out what I am missing. I am trying to cast an item from a list to a decimal. The error I am getting is Can not implicitly convert type to decimal. Thanks in advance.
public class specialTeam
{
public decimal Scores {get;set;}
public specialTeam(string awayTeam)
{
Scores = bBall.getStatList().Where(t => t.Teams == awayTeam).Select(s => s.score);
}
}
Loading
VulpesPosted Mar 1, 2012, 5:26 AM
If there's only one result then you can use the First() extension method.
P.S.
Did you remember to change the type of the Scores property to decimal[] ?
RichPosted Mar 1, 2012, 5:54 AM
VulpesPosted Mar 1, 2012, 5:49 AM
If there may be one or no results, then you can use FirstOrDefault() rather than First().
If there were no results, this would then set Scores to 0m which is the decimal type's default value.
RichPosted Mar 1, 2012, 5:47 AM
RichPosted Mar 1, 2012, 5:44 AM
public List
Scores = bBall.getStatList().Where(t => t.Teams == awayTeam).Select(s => s.score.score).ToList();
or
public decimal Scores {get;set;}
Is there an advantage by one over the other?
Sam HobbsPosted Mar 1, 2012, 5:42 AM
RichPosted Mar 1, 2012, 5:21 AM
VulpesPosted Mar 1, 2012, 5:02 AM
RichPosted Mar 1, 2012, 4:55 AM
public specialTeam(string awayTeam)
{
Scores = bBall.getStatList().Where(t => t.Teams == awayTeam).Select(s => s.score.score);
}
But now the error is Can not implicitly convert IEnumerable
VulpesPosted Mar 1, 2012, 4:43 AM
RichPosted Mar 1, 2012, 4:10 AM
Sam HobbsPosted Mar 1, 2012, 3:53 AM
That is a problem with powerful tools. Your one line is actually doing multiple things. That is good when it works but it is difficult to diagnose when it does not work.
Are you assuming that the Select method returns an item? Are you sure it does?