继承不正常 - 请帮助!! [英] inheritance not working properly -- Help please!!

查看:64
本文介绍了继承不正常 - 请帮助!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在C#中有两个类,一个是基础,另一个是从基础继承

类...都是泛型......这是第二类的定义:


公共类CNetworkServer< PlayerInfos:CNetworkClient< PlayerInfoswhere

PlayerInfos:CPlayerInfos,new()

{

}


这是问题...当我输入公共覆盖时,intellisense

应该弹出我的基类方法...而不是它弹出3种方法:

等于,GetHashCode和ToString ...


是我的定义有问题吗?这里是我的基类方法

应该被覆盖:public void Connect()...我必须在

方法中添加任何东西,所以我可以覆盖它在我继承的课程中?


我试图重建项目,但没有变化,仍然是相同的...


任何人都可以帮助拜托?


谢谢


ThunderMusic



I have two classes in C#, one is the base, the other inherits from the base
class... both are generics... Here is the definition of the second class :

public class CNetworkServer<PlayerInfos: CNetworkClient<PlayerInfoswhere
PlayerInfos : CPlayerInfos, new()
{
}

Here is the problem... when I type "public override", the intellisense
should pop with my base class methods... instead it pops with 3 methods :
Equals, GetHashCode and ToString...

Is there a problem in my definition? here''s on of my base class method that
should be overrided : public void Connect()... Must I add anything to the
method so I can override it in my inherited class?

I tried to rebuild the project, but no change, still the same...

Can anyone help please?

Thanks

ThunderMusic

推荐答案

可以你发布了一个更完整的简单代码来更好地理解你的b $ b问题?


ThunderMusic写道:
Can you post a more complete simple code to better understand your
problem?

ThunderMusic wrote:

hi,


我在C#中有两个类,一个是基础,另一个继承自基础

类......两者都是泛型。 ..这是第二类的定义:


公共类CNetworkServer< PlayerInfos:CNetworkClient< PlayerInfoswhere

PlayerInfos:CPlayerInfos,new()

{

}


这是问题......我键入public override,intellisense

应弹出我的基类方法...而不是它弹出3种方法:

Equals,GetHashCode和ToString。 ..


我的定义有问题吗?这里是我的基类方法

应该被覆盖:public void Connect()...我必须在

方法中添加任何东西,所以我可以覆盖它在我继承的课程中?


我试图重建项目,但没有变化,仍然是相同的...


任何人都可以帮助拜托?


谢谢


ThunderMusic


I have two classes in C#, one is the base, the other inherits from the base
class... both are generics... Here is the definition of the second class :

public class CNetworkServer<PlayerInfos: CNetworkClient<PlayerInfoswhere
PlayerInfos : CPlayerInfos, new()
{
}

Here is the problem... when I type "public override", the intellisense
should pop with my base class methods... instead it pops with 3 methods :
Equals, GetHashCode and ToString...

Is there a problem in my definition? here''s on of my base class method that
should be overrided : public void Connect()... Must I add anything to the
method so I can override it in my inherited class?

I tried to rebuild the project, but no change, still the same...

Can anyone help please?

Thanks

ThunderMusic


好的,我''ll发布基类和继承类(定义和1

方法,因为它太长了)


公共类CNetworkClient< PlayerInfos: IDIisposable,其中PlayerInfos:

CPlayerInfos,new()

{

public void Connect()

{

//做事情

}

}


公共类CNetworkServer< PlayerInfos:CNetworkClient< PlayerInfoswhere

PlayerInfos:CPlayerInfos,new()

{

公共覆盖//这是'它应该弹出的地方e Connect()方法,

但它不是

}


一切似乎都很正常,所以我不喜欢不明白为什么它不起作用......

重要的是要注意项目的构建(删除public

override)我刚加入CNetworkServer课程


可能是什么原因?


谢谢


ThunderMusic

< lu ******* @ hotmail.comwrote in message

news:11 ************** ********@75g2000cwc.googlegro ups.com ...
ok, I''ll post the base class and the inherited class (definition and 1
method, because it would be too long)

public class CNetworkClient<PlayerInfos: IDisposable where PlayerInfos :
CPlayerInfos, new()
{
public void Connect()
{
// Do things
}
}

public class CNetworkServer<PlayerInfos: CNetworkClient<PlayerInfoswhere
PlayerInfos : CPlayerInfos, new()
{
public override // that''s where it should pop with the Connect() method,
but it''s not
}

Everything seems normal to me, so I don''t understand why it doesn''t work...
it''s important to notice that the project builds (by removing the "public
override" I just added in the CNetworkServer class

What could be the cause?

Thanks

ThunderMusic
<lu*******@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...

您是否可以发布更完整的简单代码以更好地了解您的

问题?


ThunderMusic写道:
Can you post a more complete simple code to better understand your
problem?

ThunderMusic wrote:

> hi,

我在C#中有两个类,一个是基类,另一个继承自
基类......两个都是泛型......这是第二类的定义


公共类CNetworkServer< PlayerInfos:CNetworkClient< PlayerInfos>
其中
PlayerInfos:CPlayerInfos,new()



这是问题...当我输入公共覆盖时,intellisense
应该弹出我的基类方法...而不是它弹出3个方法

Equals,GetHashCode和ToString ......

我的定义中有问题吗?这是'我的基类方法

应该被覆盖:public void Connect()...我必须添加任何东西到

方法,所以我可以覆盖它在我继承的课堂上?

我试图重建这个项目,但是没有变化,仍然是一样的......

任何人都可以帮忙吗?

谢谢

ThunderMusic
>

I have two classes in C#, one is the base, the other inherits from the
base
class... both are generics... Here is the definition of the second class
:

public class CNetworkServer<PlayerInfos: CNetworkClient<PlayerInfos>
where
PlayerInfos : CPlayerInfos, new()
{
}

Here is the problem... when I type "public override", the intellisense
should pop with my base class methods... instead it pops with 3 methods
:
Equals, GetHashCode and ToString...

Is there a problem in my definition? here''s on of my base class method
that
should be overrided : public void Connect()... Must I add anything to
the
method so I can override it in my inherited class?

I tried to rebuild the project, but no change, still the same...

Can anyone help please?

Thanks

ThunderMusic



您需要将Connect标记为虚拟;在Java虚拟中是默认的;在C#

它不是。


Marc
You need to mark Connect as virtual; in Java virtual is the default; in C#
it isn''t.

Marc


这篇关于继承不正常 - 请帮助!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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