Actually with a little detour, you could make such a conversion work, however, it requires an extra parent class for both other classes, and an implicit operator to turn a Client into a Person (though this might not be what you were originally after)
class Program
{
public abstract class BasePerson
{
public string FirstName { get; set; }
}
public class Person : BasePerson
{
}
public class Client : BasePerson
{
public string LastName { get; set; }
public static implicit operator Client(Person p)
{
if (p == null)
{
return null;
}
return new Client { FirstName = p.FirstName };
}
}
static void Main(string[] args)
{
Person p = new Person { FirstName = "Test" };
Client c = (Client)p;
Console.WriteLine(c.FirstName);
Console.ReadLine();
}
}
which would compile and offer the FirstName to a client, with a last name possibility, however, as i said, this might not be what you were after, just a possibility to make your code compile, and run with minimal changes...
UPDATE
As discussed in the comments, if i would need to implement such a conversion, i would prefer doing it by either
which would result in:
Client c = Client.GetClientFromPerson(p);
which would result in:
Client c = new Client(p);
This would make reviewing the code by somebody else a lot easier, also possible maintenance in the future, and wouldn't require you to change the inheritance that you have now
c.LastName
?