Assume the code below. Is it possible to create a derived class using an instance of the existing base class? Or is using extension methods the best solution here?
public class TestThis
{
public void Test1()
{
A a = GetAFromExternalSystem();
B b = new B(a);
a.Value = 5;
b.Value == 5; //want this line to return true. In other words, b to hold a reference to a.
}
private A GetAFromExternalSystem()
{
return new A();
}
}
public class A
{
public string Name { get; set; }
public int Value { get; set; }
}
public class B : A
{
public B(A a)
{
this = a; //Cannot assign to 'this' because it is read-only
}
public int Ranking { get; set; }
}