I want to know how to map fields of two different objects and assign the values to it.
Eample:
public class employee
{
public int ID { get; set; }
public string Name { get; set; }
}
public class manager
{
public int MgrId { get; set; }
public string MgrName { get; set; }
}
Now I have a List object. I want to assign the values to "manager" class. Any automatic way to do that. I can do it explicitly and assigning values to it. But my object is very huge thats the problem. I dont want to use any third party tools too.
Note: It can't have any prefix for manager. It can be anything. (Ex: mgrId can be like mgrCode)
I know this post is kind old now but for other people who are looking for answer is this what you can go for.. just simply use lambda expression
var managers = employees.Select(x => new Manager()
{
MgrCode = x.ID,
MgrName = x.Name
}).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With