ralphtrent
Programmer
I have a base "Family" class. I will derive from this class for my "Father", "Mother" and "Child" class.
I want to set the last name only once in the base class. This is my code
Here is how i invoke
My goal is that fa.LastName will just take the Family.LastName value I just set, but that does not happen. I have to do this
to get my results. I was hoping I would not have to do this for all my derived classes. Now if I set last name in my derived class , then this will work
but obviously I do not want to do that.
I have searched and I could not find anything that talks about this type of implementation.
Is the problem that when Father is called, a new implementation of Family is created, therefore LastName is ""?
Thanks,
RalphTrent
I want to set the last name only once in the base class. This is my code
Code:
class Family
{
private string last_name;
public virtual string LastName { get { return last_name; } set { last_name = value; } }
}
class Father : Family{}
class Mother : Family{}
class Child : Family{}
Here is how i invoke
Code:
Family f = new Family();
f.LastName = "Smith";
Father fa = new Father();
[green]// When I do this, I get back a blank value[/green]
Console.Write(fa.LastName);
My goal is that fa.LastName will just take the Family.LastName value I just set, but that does not happen. I have to do this
Code:
fa.LastName = f.LastName;
to get my results. I was hoping I would not have to do this for all my derived classes. Now if I set last name in my derived class , then this will work
Code:
class Family
{
private string last_name = "Smith";
}
but obviously I do not want to do that.
I have searched and I could not find anything that talks about this type of implementation.
Is the problem that when Father is called, a new implementation of Family is created, therefore LastName is ""?
Thanks,
RalphTrent