[Solved] .NET Code sample to find out what is wrong in the code [closed]


a.) In the above code, I am not sure what (DateTime?) startDate means?

This is saying cast startDate to a DateTime? object. startDate might be a DateTime and for purposes of this for loop, it’s being cast to a nullable DateTime (DateTime?)

b.) scorecardMonths on the very last line… sees to be some object..

Agreed, it looks to be a list, which the .Add implies it’s a List< ScorecardMonth>

c.) The question online says, what is wrong with the code? Line #5… Scorecards doesn’t have an object name… I would like to know if anything else stands out?

I’d throw out the whole thing and start over. I kind of understand what it’s doing, but it’s written in a difficult to understand way – this seems easier for me to understand, ymmv:

for (var i = 0; i <= 11; i++)
{
    month = startDate.AddMonths(i);
    var scm = new ScorecardMonth { 
                        TheMonth = month, //this is a DateTime..
                        Scorecards = new List<Scorecard>()
    };

    scorecardsInMonth = scorecards.FindAll(a => a.TheMonth == month)
                                  .OrderBy(b => b.GoalType));
    scm.Scorecards.AddRange(scorecardsInMonth);

    scorecardMonths.Add(scm);
}

2

solved .NET Code sample to find out what is wrong in the code [closed]