I am trying to populate the List template with a class (Student) inheriting from two interfaces (IIndividual and IGuardian). Population succeeds quite OK. The problem am having now is that the last element replaces the older elements and overrides them. Am confused.
interface IIndividual
{
String Name { get; set; }
String Number { get; set; }
String Address { get; set; }
}
interface IGuardian
{
String Name { get; set; }
String Number { get; set; }
String Address { get; set; }
}
class Student: IIndividual, IGuardian
{
String IIndividual.Name { get; set; }
String IIndividual.Number { get; set; }
String IIndividual.Address { get; set; }
String IGuardian.Name { get; set; }
String IGuardian.Number { get; set; }
String IGuardian.Address { get; set; }
public void output()//testing
{
IIndividual i = this as IIndividual;
Console.WriteLine("Individual Name = {0}", i.Name);
Console.WriteLine("Individual Number = {0}", i.Number);
Console.WriteLine("Individual Address= {0}", i.Address);
IGuardian g = this as IGuardian;
Console.WriteLine("Guardian Name = {0}", g.Name);
Console.WriteLine("Guardian Number = {0}", g.Number);
Console.WriteLine("Guardian Address= {0}", g.Address);
}
}
static void Main(string[] args)
{
List<Student> s = new List<Student>();
Student ss = new Student();
IIndividual ii = ss as IIndividual;
IGuardian gg = ss as IGuardian;
gg.Name = "Kinyo Yemi";
gg.Number = "08012345678";
gg.Address = "Bunker Street";
ii.Name = "Hope Ajayi";
ii.Number = "08185543124";
ii.Address = "Metropolitan Council";
s.Add(ss);
/////////////////////
gg.Name = "Awwal Kadi";
gg.Number = "08072523245";
gg.Address = "R32 Damboa";
ii.Name = "Morak Suleiman";
ii.Number = "08535755543";
ii.Address = "Sederal Low Cost";
s.Add(ss);
foreach (var x in s)
{
x.output();
Console.WriteLine();
}
Console.Read();
}