How to copy value from class X to class Y with the same property name in c#?
Posted
by Samnang
on Stack Overflow
See other posts from Stack Overflow
or by Samnang
Published on 2009-02-10T08:40:21Z
Indexed on
2010/05/23
4:30 UTC
Read the original article
Hit count: 236
Suppose I have two classes:
public class Student
{
public int Id {get; set;}
public string Name {get; set;}
public IList<Course> Courses{ get; set;}
}
public class StudentDTO
{
public int Id {get; set;}
public string Name {get; set;}
public IList<CourseDTO> Courses{ get; set;}
}
I would like to copy value from Student class to StudentDTO class:
var student = new Student();
StudentDTO studentDTO = student;
How can I do that by reflection or other solution?
© Stack Overflow or respective owner