什么相当于德尔福的“重新引入”? [英] What is the equivalent of Delphi's "reintroduce"?

查看:91
本文介绍了什么相当于德尔福的“重新引入”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从继承的类中覆盖一个方法,但新的

方法与继承的类有不同的签名。例如:


A级{

private void Init(){

//代码

}

}


B级:A {

private void Init(字符串文本){

base.Init();

//用text做一些事情

}

}


我不想看到A级的Init()版本。 B类

的任何实例都应该只看到Init(文本)。我知道这可以在Delphi中使用

重新引入修饰符,但我在C#中找不到方法。 覆盖和

" new"修饰符也没有帮助。

-

问候,

木炭

解决方案

它没有帮助,因为方法Init没有被继承,它应该是

声明为受保护。


Chazza < EM *** @ address.com>在消息中写道

新闻:eP ************** @ TK2MSFTNGP09.phx.gbl ...

我想覆盖来自继承类的方法,但新的
方法与继承的类具有不同的签名。示例:

A类{
私有空间Init(){
//代码
}
}
B类:A {
private void Init(string text){
base.Init();
//用text进行
}
}
/>
我不想看到A类的Init()版本。 B类
的任何实例都应该只能看到Init(文本)。我知道这在Delphi中使用
reintroduce修饰符是可能的,但我在C#中找不到方法。 覆盖和
新修饰符也没有帮助。

-
问候,
木炭



< blockquote>在我的例子中,这是一个错字。我注意到了,但认为你可以

忽略它。


试试,


class一个

{

保护虚拟空虚Init()

{

//代码

}

}


B级:A

{

protected override void Init( )

{

base.Init();

//用text做一些事情

}

}


问候,

菲尔。


" Chazza"写道:

在我的例子中,这是一个错字。我注意到了,但认为你可以忽略它。



I would like to override a method from an inherited class, but the new
method has a different signature to the inherited class. Example:

class A {
private void Init() {
// code
}
}

class B : A {
private void Init(string text) {
base.Init();
// do something with "text"
}
}

I don''t want to see class A''s version of Init(). Any instance of class B
should only see Init(text). I know this is possible in Delphi using the
reintroduce modifier, but I couldn''t find a way in C#. The "override" and
"new" modifiers didn''t help either.
--
Regards,
Charcoal

解决方案

it didn''t help because the method Init was not inherited, it should be
declared as protected.

"Chazza" <em***@address.com> wrote in message
news:eP**************@TK2MSFTNGP09.phx.gbl...

I would like to override a method from an inherited class, but the new
method has a different signature to the inherited class. Example:

class A {
private void Init() {
// code
}
}

class B : A {
private void Init(string text) {
base.Init();
// do something with "text"
}
}

I don''t want to see class A''s version of Init(). Any instance of class B
should only see Init(text). I know this is possible in Delphi using the
reintroduce modifier, but I couldn''t find a way in C#. The "override" and
"new" modifiers didn''t help either.
--
Regards,
Charcoal



That was a typo in my example. I noticed that but thought that you could
just ignore that.


Try,

class A
{
protected virtual void Init()
{
// code
}
}

class B : A
{
protected override void Init()
{
base.Init();
// do something with "text"
}
}

Regards,
Phil.

"Chazza" wrote:

That was a typo in my example. I noticed that but thought that you could
just ignore that.



这篇关于什么相当于德尔福的“重新引入”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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