自定议类有什么问题

longyuhong8888 2009-11-30 01:37:26
各位帮我看看,这个自定议类有什么问题,为何我在用BindingSource mBS = new myBindingSource();后,mBS.blnSord没有出现,而用myBindingSource mBS = new myBindingSource();时,可见mBS.blnSord
    class myBindingSource : System.Windows.Forms.BindingSource

{
private bool mSording;

//自定义属性
public bool blnSord
{
get
{
return mSording;
}
set
{
mSording = value;
}
}

public override bool SupportsSorting
{
get { return false; }
}
}
...全文
48 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
宝_爸 2009-11-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 longyuhong8888 的回复:]
那是不是我重寫的SupportsSorting也沒有取作用了?
引用 2 楼 findcaiyzh 的回复:
BindingSource mBS = new myBindingSource();
mBS的类型是BindingSource, 因此没有办法访问你的继承类中的方法。

[/Quote]

有作用,因为它的定义是:
public virtual bool SupportsSorting { get; }
virtual的意思是后捆定,也就是执行的时候,根据对象的类型(注意不是变量类型)进行调用。
因此mBS.SupportsSorting 调用的是你继承类的的方法,因为mBS指向的对象类型是myBindingSource

longyuhong8888 2009-11-30
  • 打赏
  • 举报
回复
那是不是我重寫的SupportsSorting也沒有取作用了?
[Quote=引用 2 楼 findcaiyzh 的回复:]
BindingSource mBS = new myBindingSource();
mBS的类型是BindingSource, 因此没有办法访问你的继承类中的方法。
[/Quote]
宝_爸 2009-11-30
  • 打赏
  • 举报
回复
BindingSource mBS = new myBindingSource();
mBS的类型是BindingSource, 因此没有办法访问你的继承类中的方法。
wuyq11 2009-11-30
  • 打赏
  • 举报
回复
BindingSource mBS = new myBindingSource
转为父类对象。

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧