重载抽象类型 [英] overloading abstract type

查看:74
本文介绍了重载抽象类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在子类中重载抽象类型方法?


例如


public abstract void BaseMethod()

{

//做点什么

}


//在儿童班里

public override void BaseMethod(int i)

{

//做点什么

}


-

---------------------------------------- ------------------------------

这是一个不受监控的电子邮件帐户。请不要直接回复

这封电子邮件。由技术人员组成的NG的常见电子邮件帐户。

How can I overload abstract type method in child class?

e.g.

public abstract void BaseMethod()
{
// do something
}

// in child class
public override void BaseMethod(int i)
{
// do something
}

--
----------------------------------------------------------------------
This is an unmonitored email account. Please do not reply directly to
this email. Common email account for NG by group of techies.

推荐答案

void BaseMethod(int)不会覆盖void BaseMethod();签名

是不同的。要实现抽象BaseMethod(),请使用:


public override void BaseMethod(){}

如果你想要一个抽象的BaseMethod(int)那么在父类

类中定义,然后你可以在子类中覆盖它。否则在子类中声明它是虚拟的,如果你想要这个'

专业化/重载定义的那么。


--Bob


Pohihihi写道:
void BaseMethod(int) does not override void BaseMethod(); the signatures
are different. To implement abstract BaseMethod() use:

public override void BaseMethod() {}

If you want an abstract BaseMethod(int) then define that in the parent
class, then you can override it in the child class. Otherwise declare
it virtual in the child class if that''s where you want this
specialization / overload to be defined.

--Bob

Pohihihi wrote:
如何在子类中重载抽象类型方法?

例如

公共抽象void BaseMethod()
//
//做点什么

//在子类中
public override void BaseMethod(int i)
{
//做点什么
}
How can I overload abstract type method in child class?

e.g.

public abstract void BaseMethod()
{
// do something
}

// in child class
public override void BaseMethod(int i)
{
// do something
}



所以基本上你说的是我想重载一个基类

方法我需要在基本抽象中声明为vertial而不是抽象

class?


这是有效的,我的问题的第二部分是它将显示超载

intellisence。有没有办法隐藏超载的基类方法

并覆盖我班级的用户?它是相同的程序集和名称空间。

据我所知它不可能,是吗?

Bob Grommes < bo*@bobgrommes.com>在消息中写道

news:或************** @ TK2MSFTNGP11.phx.gbl ...
So basically what you are saying that if I want to overload a baseclass
method I need to declare is as vertual and not abstract in base abstract
class?

That works, second part of my problem is that it will show overloaded in
intellisence. Is there a way to hide base class method that are overloaded
and overridden to the users of my class? It is same assembly and namespace.
As far as I know it can''t be, is that right?
"Bob Grommes" <bo*@bobgrommes.com> wrote in message
news:Or**************@TK2MSFTNGP11.phx.gbl...
void BaseMethod(int)不会覆盖void BaseMethod();签名
是不同的。要实现抽象BaseMethod(),请使用:

public override void BaseMethod(){}
如果你想要一个抽象的BaseMethod(int),那么在父
class,然后你可以在子类中覆盖它。否则在子类中声明它是虚拟的,如果你想要定义这个特化/
重载的话。

--BOB
Pohihihi写道:
void BaseMethod(int) does not override void BaseMethod(); the signatures
are different. To implement abstract BaseMethod() use:

public override void BaseMethod() {}

If you want an abstract BaseMethod(int) then define that in the parent
class, then you can override it in the child class. Otherwise declare it
virtual in the child class if that''s where you want this specialization /
overload to be defined.

--Bob

Pohihihi wrote:
如何在子类中重载抽象类型方法?
例如
公共抽象void BaseMethod()
//
//在子类中
}
//公共覆盖void BaseMethod(int i)
{
//做某事
}
How can I overload abstract type method in child class?
e.g.
public abstract void BaseMethod()
{
// do something
}
// in child class
public override void BaseMethod(int i)
{
// do something
}



不,如果你声明它是虚拟的,那么你必须提供一个

的实现。你想完全添加另一个参数,这是不可能的,因为基类不会知道这个参数列表。


第二个问题是如果覆盖方法,则不会出现问题。如果你把一个方法重载为
,你为什么要隐藏基类版本?


我觉得你需要稍微看一下你的类设计更好,因为

你正在做一些非传统的东西。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard。 caspershouse.com


" Pohihihi" <无***** @ hotmail.com>在消息中写道

news:uE ************* @ TK2MSFTNGP15.phx.gbl ...
No, if you declare it as virtual, you then have to provide an
implementation. You wanted to add another parameter altogether, which is
impossible, because the base class wouldn''t know about this parameter list.

The second issue is a non-issue if you override a method. If you
overload a method, why do you want to hide the base class versions?

I think you need to look at your class design a little bit better, since
you are doing some pretty non-conventional stuff.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pohihihi" <no*****@hotmail.com> wrote in message
news:uE*************@TK2MSFTNGP15.phx.gbl...
基本上你说的是什么如果我想重载一个基类
方法,我需要在基础抽象类中声明是否为vertial而不是抽象?

这是有效的,我问题的第二部分是它将显示超载的智能。有没有办法隐藏重载的基类方法
并覆盖我的类用户?它是相同的程序集和命名空间。据我所知它不可能,是吗?

Bob Grommes < bo*@bobgrommes.com>在消息中写道
新闻:或************** @ TK2MSFTNGP11.phx.gbl ...
So basically what you are saying that if I want to overload a baseclass
method I need to declare is as vertual and not abstract in base abstract
class?

That works, second part of my problem is that it will show overloaded in
intellisence. Is there a way to hide base class method that are overloaded
and overridden to the users of my class? It is same assembly and
namespace. As far as I know it can''t be, is that right?
"Bob Grommes" <bo*@bobgrommes.com> wrote in message
news:Or**************@TK2MSFTNGP11.phx.gbl...
void BaseMethod(int)不会覆盖void BaseMethod();签名
是不同的。要实现抽象BaseMethod(),请使用:

public override void BaseMethod(){}
如果你想要一个抽象的BaseMethod(int),那么在父
class,然后你可以在子类中覆盖它。否则在子类中声明它是虚拟的,如果你想要定义这个特化/
重载的话。

--BOB
Pohihihi写道:
void BaseMethod(int) does not override void BaseMethod(); the signatures
are different. To implement abstract BaseMethod() use:

public override void BaseMethod() {}

If you want an abstract BaseMethod(int) then define that in the parent
class, then you can override it in the child class. Otherwise declare it
virtual in the child class if that''s where you want this specialization /
overload to be defined.

--Bob

Pohihihi wrote:
如何在子类中重载抽象类型方法?
例如
公共抽象void BaseMethod()
//
//在子类中
}
//公共覆盖void BaseMethod(int i)
{
//做某事
}
How can I overload abstract type method in child class?
e.g.
public abstract void BaseMethod()
{
// do something
}
// in child class
public override void BaseMethod(int i)
{
// do something
}




这篇关于重载抽象类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆