C#ベースタイプ変換

2080 ワード

 class Preson
{
public int i = 30;
public int n = 40;
public int add(int a, int b)
{
return a + b;
}

}

class Water : Preson
{
public int cut(int b, int c)
{
return b - c;
}

}
   class Program
{
static void Main(string[] args)
{
Preson p = new Water();//
p.add(2,4);
       Water s =(Water)new Preson();// , , 。InvalidCastException 
Water w = new Water();// , , 。
       w.cut(2, 3);
       bool isbol = (w is Preson);//is bool 。 。 true      

        Preson pp = new Preson();         bool isbol = (pp is Water);//ここではだめだ
            Preson pr = w as Preson;//clr w preson , null 。  null,as , , , null。

}
}