Let’s say I have 2 classes like this:
public class A
{
public string P1{ get; set; }
public string P2{ get; set; }
}
public class B
{
public string P3{ get; set; }
public string P4{ get; set; }
}
and I need a class like this:
public class C
{
public string P1{ get; set; }
public string P2{ get; set; }
public string P3{ get; set; }
public string P4{ get; set; }
}
it it possible for the class C to use class A and B instead of re-declaring all the properties ?
(I need this for DTOs)
You can’t, as multiple inheritance is only for interfaces in C#.
Hacks
I:
II:
III:
As for the DTO, maybe these links 1; 2 could be useful:
If not, you could build your class dynamically using reflection.
Build dynamically a new
Cclass containing all the public properties of bothAandB.