怎么获取父类方法的返回值?
例如public partial class A
{
public Boolean fun()
{
if (条件)
return true;
else
return false;
}
}
public partial class B : A
{
public Boolean fun()
{
//如果父类中的fun返回真才执行下面的语句应该怎么写?
//不知道怎么获取父类该方法执行时返回的值
.......
}
}
例如public partial class A
{
public Boolean fun()
{
if (条件)
return true;
else
return false;
}
}
public partial class B : A
{
public Boolean fun()
{
//如果父类中的fun返回真才执行下面的语句应该怎么写?
//不知道怎么获取父类该方法执行时返回的值
.......
}
}
{
public Boolean fun()
{ if (base.fun())
{
//在这里写
}
...;
}
}
{
public void Test()
{
Console.WriteLine("");
}
}
public class ChildClass: Base
{
public new void Test()
{
Console.WriteLine("");
}
}
static void Main(string[] args)
{ ChildClass d = new ChildClass();
d.Test();
((Base)d).Test();
}
{
public Boolean fun()
{
//如果不想执行A类里的fun()应该怎么写?
}
}
public partial class A
{
public Boolean fun()
{
System.Console.Write("A.fun");
return true;
}
}public partial class B : A
{
public Boolean fun()
{
return false;
}
}
public partial class A
{
public Boolean fun()
{
System.Console.Write("A.fun");
return true;
}
}public partial class B : A
{
public Boolean fun()
{
return false;
}
}
直接这么写系统提示:
B.fun() 隐藏了继承的成员A.fun()。如果是有意隐藏,请使用关键字 new。
{
public Boolean fun()
{
System.Console.Write("A.fun");
return true;
}
}public partial class B : A
{
public Boolean fun()
{
//如果想继承A的方法,直接这么写对不对?
return false;
}
}
直接这么写系统提示:
B.fun() 隐藏了继承的成员A.fun()。如果是有意隐藏,请使用关键字 new。
2 public B:A
{
A a=new A();
....
fun()
{
a.fun()
}
}