I'm having a hard time proving the value in creating and using interfaces. I thought maybe if my derived classes all had the same base class or interface in this case, I could cast between them like so...
Didn't happen.
Let me know what you think.
Code:
class TestInterface{
[STAThread]
static void Main(string[] args){
Queen queen = new Queen();
King king = new King();
Queen Newqueen = (Queen)king;
Console.WriteLine(Newqueen.zz);
King Newking = (King)queen;
Console.WriteLine(Newking.yy);
}
}
interface IPiece{
string a();
string bb{
get;
}
string cc{
set;
}
}
class King:IPiece{
public string a(){
return null;
}
public string bb{
get{return null;}
}
public string cc{
set{}
}
public string yy{
get{return "ee";}
}
}
class Queen:IPiece{
public string a(){
return null;
}
public string bb{
get{return null;}
}
public string cc{
set{}
}
public string zz{
get{return "ww";}
}
}
Didn't happen.
Let me know what you think.