c# Converting from one object to another without using foreach I am return an student object from my database and I want to convert it into a StudentRecoredRequest model. The way i have implement is shown below. I was wondering if there was a nicer way to convert from the student object to studentsystemrecordrequest. Thanks
        var result = await _context.Student.ToListAsync();
        var studentInfo = new List&lt;StudentSystemRecordRequest&gt;();
        foreach(var student in result)
        {
            var stud = new StudentSystemRecordRequest
            {
                FirstName = student.FirstName,
                LastName = student.SurName,
                DateOfBirth = student.DateOfBirth,
                Address = student.Address1
            };
            studentInfo.Add(stud);
        }
You can use the LINQ syntax:
var studentInfo = 
    (from student in result
     select new StudentSystemRecordRequest
        {
            FirstName = student.FirstName,
            LastName = student.SurName,
            DateOfBirth = student.DateOfBirth,
            Address = student.Address1
        }
    ).ToList();

If you are happy with IEnumerable instead of List, you can omit ToList(), but keep in mind that in that case the resulting enumerable will be lazy, which means that the elements will be created only when the result is enumerated. But since result is probably a list, which is strict, it should not be a problem.