It's very straightforward. What you want is called inheritance in C# world.
Code:
class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
class Gender : Person
{
public bool IsMale { get; set; }
public Gender(string name, int age, bool ismale)
{
Name = name;
Age = age;
IsMale = ismale;
}
}
or if you know that you will not instantiate person class alone, just use it as base, you can make it abstract and expand from it:
Code:
abstract class Person
{
public string Name { get; set; }
public int Age { get; set; }
protected Person(string name, int age)
{
Name = name;
Age = age;
}
}
class Gender : Person
{
public bool IsMale { get; set; }
public Gender(string name, int age, bool ismale) :base(name, age)
{
IsMale = ismale;
}
}
Or just use interface instead of base class
Code:
interface IPerson
{
string Name { get; set; }
int Age { get; set; }
}
class Gender : IPerson
{
public Gender(string name, int age, bool ismale)
{
Name = name;
Age = age;
IsMale = ismale;
}
public string Name { get; set; }
public int Age { get; set; }
public bool IsMale { get; set; }
}
or you can use composition instead of inheritance
Code:
sealed class Person
{
public string Name { get; set; }
public int Age { get; set; }
public Person(string name, int age)
{
Name = name;
Age = age;
}
}
class Gender
{
private readonly Person _person;
public Gender(string name, int age, bool ismale)
{
_person = new Person(name, age);
IsMale = ismale;
}
public string Name { get { return _person.Name; } }
public int Age { get { return _person.Age; } }
public bool IsMale { get; set; }
}
EDIT:
Remember that properties don't work in Unity if you want to add parameter field to your asset. You need public variable, not property like I used here.