tags:

views:

60

answers:

2

Hi,

I have the following....

var jobsApplications = ( from applications in db.applications
                        where applications.employeeId == LogedUser.Id
 select new { applications.id, applications.jobId, applications.confirmationDate });

Now I want to navigate this result like

foreach "something" in jobsApplications

But I don't now what to put in something since the select new create a new class.

Any suggestions

+1  A: 

Consider using Array.ForEach() to iterate through your IEnumerable or List. This is a bit more heavyweight.

 Array.ForEach(jobsApplication, jobApp => {

    if (jobApp.City == "Chicago")
    {
      jobApp.Approved = true;
    }
});

If you want a simple foreach, then you can type the anonymous class as var

foreach (var jobApp in jobApplications)
{
     if (jobApp.City == "Chicago")
    {
      jobApp.Approved = true;
    }
}
p.campbell
+4  A: 

I guess you can let the compiler do the work for you:

foreach (var application in jobApplications)
{
    // use the application wisely
}
Fredrik Mörk
This is in fact one of the reasons they created var. For referencing anonymous types in a type-safe way.
Matt
yes. var is the only way to do this as you are projecting out an anonymous type.
Darren Kopp
What an intelligent compiler..And of course ProgrammerThanks Mr. Fredrik
roncansan