VB与C#语言挑战问题 [英] VB vs. C# language challenge question

查看:55
本文介绍了VB与C#语言挑战问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


下面有两个等效的(?)C#和VB.Net代码片段。

虽然C#版本编译没有警告由于编译错误BC30149,VB.Net版本没有
编译:类''c2''必须实现''Sub

m1()''用于界面''i1''。


是否意味着必须在VB界面中实现,即使它已经在基类中非显式实现了

c1?


如何在不改变c1类*的情况下编译这个VB代码*? - 那就是

约束!

我无法在VB中编译它,而在C#中它只是小菜一碟。


动机:我想通过

派生类中指定的接口访问基类方法。

听起来很奇怪,在C#中它的工作方式与预期一致 - 测试你自己:i1

c = new c2(); c.m1();


谢谢,

Tomasz

PS。此消息也已发布到microsoft.public.dotnet.framework,

但这个组可能是这个问题的更好地方。


// C#版本

class c1 {

public virtual void m1(){

}

}


class c2:c1,i1 {

}


公共接口i1 {

void m1( );

}


''VB版本

类c1

公共可覆盖子m1( )

结束次级

结束班级


班级c2

继承c1

实现i1

结束班级


公共接口i1

Sub m1()

结束界面

Hello,

Below there are two equivalent(?) pieces of C# and VB.Net code.
While the C# version compiles with no warning, the VB.Net version does not
compile due to the compiler error BC30149: Class ''c2'' must implement ''Sub
m1()'' for interface ''i1''.

Does it mean that in VB interface must be implemented, even if it is already
non-explicitly implemented in the base class c1?

How to make this VB code compile *without altering the c1 class* ? - that is
the constraint!
I can not get it compile in VB, while in C# it is just a piece of cake.

Motivation: I want to access base class methods by interface specified in a
derived class.
As strange as it sounds, in C# it works just as expected - test yourself: i1
c = new c2(); c.m1();

Thank you,

Tomasz
PS. this message has also been posted to microsoft.public.dotnet.framework,
but this group may be a better place for this question.

// C# version
class c1 {
public virtual void m1() {
}
}

class c2 : c1, i1 {
}

public interface i1 {
void m1();
}

'' VB version
Class c1
Public Overridable Sub m1()
End Sub
End Class

Class c2
Inherits c1
Implements i1
End Class

Public Interface i1
Sub m1()
End Interface

推荐答案

为什么要打扰?


您之前的相同帖子已在 microsoft.public.dotnet.framework。以及那里的回复

都是正确的并解释了情况的理解ely。

" Tomasz Jastrzebski" < oe **** @ nospam.nospamwrote in message

新闻:Oj ************** @ TK2MSFTNGP06.phx.gbl ...
Why have you bothered?

Your earlier identical post has been discussed in
microsoft.public.dotnet.framework some hours ago., and the responses there
were both correct and explained the situation comprehensively.
"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:Oj**************@TK2MSFTNGP06.phx.gbl...

您好,


下面有两个等效的(?)C#和VB.Net代码。

虽然C#版本没有警告编译,但由于编译器错误BC30149,VB.Net版本没有编译
:类''c2''必须实现''Sub

m1()''用于界面''i1''。


这是否意味着在VB界面中必须实现,即使它是

已经在基类c1中非显式实现了


如何在不改变c1类*的情况下编译这个VB代码*? - 那个



约束!

我无法在VB中编译它,而在C#中它只是小菜一碟。


动机:我想通过

a

派生类中指定的接口访问基类方法。

听起来很奇怪,在C#中它的效果与预期一样 - 测试你自己:

i1

c = new c2(); c.m1();


谢谢,

Tomasz

PS。此消息也已发布到

microsoft.public.dotnet.framework,但这个小组可能是一个更好的地方

这个问题。

// C#版

class c1 {

public virtual void m1(){

}

}


class c2:c1,i1 {

}


公共接口i1 {

void m1();

}


''VB版

类c1

Public Overridable Sub m1()

End Sub

结束班级


班级c2

继承c1

实现i1

结束类


公共接口i1

Sub m1()

结束界面
Hello,

Below there are two equivalent(?) pieces of C# and VB.Net code.
While the C# version compiles with no warning, the VB.Net version does not
compile due to the compiler error BC30149: Class ''c2'' must implement ''Sub
m1()'' for interface ''i1''.

Does it mean that in VB interface must be implemented, even if it is
already
non-explicitly implemented in the base class c1?

How to make this VB code compile *without altering the c1 class* ? - that
is
the constraint!
I can not get it compile in VB, while in C# it is just a piece of cake.

Motivation: I want to access base class methods by interface specified in
a
derived class.
As strange as it sounds, in C# it works just as expected - test yourself:
i1
c = new c2(); c.m1();

Thank you,

Tomasz
PS. this message has also been posted to
microsoft.public.dotnet.framework, but this group may be a better place
for this question.

// C# version
class c1 {
public virtual void m1() {
}
}

class c2 : c1, i1 {
}

public interface i1 {
void m1();
}

'' VB version
Class c1
Public Overridable Sub m1()
End Sub
End Class

Class c2
Inherits c1
Implements i1
End Class

Public Interface i1
Sub m1()
End Interface



问题似乎很明显。

什么我正在寻找*解决方案* - 这个新闻组可能是一个更好的

的地方。

Tomasz


" Stephany杨" < noone @ localhostwrote in message

news:OX ************** @ TK2MSFTNGP05.phx.gbl ...
The problem seems to be quite obvious.
What I am looking for is a *solution* - this newsgroup might be a better
place.
Tomasz

"Stephany Young" <noone@localhostwrote in message
news:OX**************@TK2MSFTNGP05.phx.gbl...

你为何烦恼?


你早前的相同帖子已在

microsoft.public.dotnet.framework中讨论过几个小时前那些回复

都是正确的,并全面解释了这种情况。


Tomasz Jastrzebski < oe **** @ nospam.nospamwrote in message

新闻:Oj ************** @ TK2MSFTNGP06.phx.gbl ...
Why have you bothered?

Your earlier identical post has been discussed in
microsoft.public.dotnet.framework some hours ago., and the responses there
were both correct and explained the situation comprehensively.
"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:Oj**************@TK2MSFTNGP06.phx.gbl...

>您好,

下面有两个等效的(?)C#和VB.Net代码。
而C#版本编译时没有任何警告,VB.Net版本由于编译器错误而无法编译BC30149:类''c2''必须实现''Sub
m1()''用于接口''i1''。

这是否意味着在VB界面中必须实现,即使它已经在基类c1中非显式实现了?

如何在不改变c1类*的情况下编译这个VB代码*? -
是约束!
我无法在VB中编译它,而在C#中它只是一块蛋糕。

动机:我想要通过
派生类中指定的接口访问基类方法。
听起来很奇怪,在C#中它的工作方式与预期一样 - 测试自己:
i1 c = new c2(); c.m1();

谢谢,

Tomasz
PS。此消息也已发布到
microsoft.public.dotnet.framework,但这个小组对于这个问题可能是一个更好的地方。

// C#version
class c1 {
public virtual void m1(){
}
}
类c2:c1,i1 {
}
<公共接口i1 {
void m1();
}
''VB版
类c1
Public Overridable Sub m1()<结束分类

分类c2
继承c1
实现i1
结束类

公共接口i1
Sub m1()
结束界面
>Hello,

Below there are two equivalent(?) pieces of C# and VB.Net code.
While the C# version compiles with no warning, the VB.Net version does
not
compile due to the compiler error BC30149: Class ''c2'' must implement ''Sub
m1()'' for interface ''i1''.

Does it mean that in VB interface must be implemented, even if it is
already
non-explicitly implemented in the base class c1?

How to make this VB code compile *without altering the c1 class* ? - that
is
the constraint!
I can not get it compile in VB, while in C# it is just a piece of cake.

Motivation: I want to access base class methods by interface specified in
a
derived class.
As strange as it sounds, in C# it works just as expected - test yourself:
i1
c = new c2(); c.m1();

Thank you,

Tomasz
PS. this message has also been posted to
microsoft.public.dotnet.framework, but this group may be a better place
for this question.

// C# version
class c1 {
public virtual void m1() {
}
}

class c2 : c1, i1 {
}

public interface i1 {
void m1();
}

'' VB version
Class c1
Public Overridable Sub m1()
End Sub
End Class

Class c2
Inherits c1
Implements i1
End Class

Public Interface i1
Sub m1()
End Interface




我会避免VB所有这些,它将在下一个版本中从Visual

Studio中删除。他们打算用另一种叫做D /


的语言取代它。史蒂夫雷欧文


thomas写道:
I would just avoid VB all together, its about to be dropped from Visual
Studio in the next release. They plan to replace it with another
language called D@

Steve Ray Irwin

thomas wrote:

问题似乎很明显。

我正在寻找的是*解决方案* - 这个新闻组可能更好/>
地方。

Tomasz


" Stephany Young" < noone @ localhostwrote in message

news:OX ************** @ TK2MSFTNGP05.phx.gbl ...
The problem seems to be quite obvious.
What I am looking for is a *solution* - this newsgroup might be a better
place.
Tomasz

"Stephany Young" <noone@localhostwrote in message
news:OX**************@TK2MSFTNGP05.phx.gbl...

你为何烦恼?


你早前的相同帖子已在

microsoft.public.dotnet.framework中讨论过几个小时前并且那里的回复

都是正确的并且全面地解释了这种情况。

Tomasz Jastrzebski < oe **** @ nospam.nospamwrote in message

新闻:Oj ************** @ TK2MSFTNGP06.phx.gbl ...
Why have you bothered?

Your earlier identical post has been discussed in
microsoft.public.dotnet.framework some hours ago., and the responses there
were both correct and explained the situation comprehensively.
"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:Oj**************@TK2MSFTNGP06.phx.gbl...

您好,


下面有两个等效的(?)C#和VB.Net代码。

虽然C#版本没有警告编译,但由于编译器错误BC30149,VB.Net版本确实没有

编译
:类''c2''必须实现''sub

m1()''用于界面''i1''。


这是否意味着在VB界面必须实现,即使它已经

已经

在基类c1中非显式实现了?


如何使这个VB代码编译*而不改变c1班*? - 那个



约束!

我无法在VB中编译它,而在C#中它只是小菜一碟。


动机:我想通过

a

派生类中指定的接口访问基类方法。

听起来很奇怪,在C#中它的效果与预期一样 - 测试你自己:

i1

c = new c2(); c.m1();


谢谢,

Tomasz

PS。此消息也已发布到

microsoft.public.dotnet.framework,但这个小组可能是一个更好的地方

这个问题。

// C#版

class c1 {

public virtual void m1(){

}

}


class c2:c1,i1 {

}


公共接口i1 {

void m1();

}


''VB版

类c1

Public Overridable Sub m1()

End Sub

结束班级


班级c2

继承c1

实现i1

结束类


公共接口i1

Sub m1()

结束界面
Hello,

Below there are two equivalent(?) pieces of C# and VB.Net code.
While the C# version compiles with no warning, the VB.Net version does
not
compile due to the compiler error BC30149: Class ''c2'' must implement ''Sub
m1()'' for interface ''i1''.

Does it mean that in VB interface must be implemented, even if it is
already
non-explicitly implemented in the base class c1?

How to make this VB code compile *without altering the c1 class* ? - that
is
the constraint!
I can not get it compile in VB, while in C# it is just a piece of cake.

Motivation: I want to access base class methods by interface specified in
a
derived class.
As strange as it sounds, in C# it works just as expected - test yourself:
i1
c = new c2(); c.m1();

Thank you,

Tomasz
PS. this message has also been posted to
microsoft.public.dotnet.framework, but this group may be a better place
for this question.

// C# version
class c1 {
public virtual void m1() {
}
}

class c2 : c1, i1 {
}

public interface i1 {
void m1();
}

'' VB version
Class c1
Public Overridable Sub m1()
End Sub
End Class

Class c2
Inherits c1
Implements i1
End Class

Public Interface i1
Sub m1()
End Interface


这篇关于VB与C#语言挑战问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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