If I have these two classes:
public class StudyClass
{
public string className { get; set; }
public List<Student> students { get; set; }
}
public class Student
{
public string studentName { get; set; }
}
Then I can initialize the StudyClass object like that:
var classObject = GetClassData(); // returns a big object with many properties that I don't need
var studyClass= new StudyClass() {
className = classObject.className
}
foreach(var student in classObject.students)
{
studyClass.students.add(new Student() {
studentName = student.Name
});
}
Is it possible to do it in a more simple way, by doing something like:
var classObject = GetClassData(); // returns a big object with many properties that I don't need
var studyClass= new StudyClass() {
className = classObject.className,
students = classObject.students.ForEach...// i am stuck here
}
If it's possible, is there any performance benefit or drawback by doing that ?
ifstatement body should be surrounded by curly braces placed on the new line. Try using FormatDocument option in VS with default C# settings - it will move brace into a new line.