473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

VB vs. C# language challenge question

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
Nov 29 '06 #1
13 2341
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...
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

Nov 29 '06 #2
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...
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...
>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


Nov 30 '06 #3
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:
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...
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...
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
Nov 30 '06 #4
Ignore him, he's wrong. VB is not going to be dropped.
Robin S.
-----------------------------
"Master Programmer" <ma***************@outgun.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
>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:
>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...
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...
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

Nov 30 '06 #5
"Master Programmer" <ma***************@outgun.comschrieb:
>I would just avoid VB all together, its about to be dropped from Visual
Studio in the next release.
Which is again complete nonsense.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 30 '06 #6
Tomasz Jastrzebski wrote:
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?
"non-explicitly implemented in the base class"
There's no such thing. Try this:

Dim oc1 As i1 = New c1

It won't work. c1 /does not/ implement i1 because you have to
explicitly tell the compiler that it does so, with the Implements
statement on the class and the Implements clause on the relevant method(s).

Why should a method "implement" an item on an Interface just because it
happens to have the same name (actually, same signature)?
It would make adding a new Iterface to an existing class quite a
nerve-racking experience.
How to make this VB code compile *without altering the c1 class* ?
Not too difficult:
Class c1
Public Overridable Sub m1()
End Sub
End Class

Class c2
Inherits c1
Implements i1
Public Overrides Sub m1() Implements i1.m1
End Class
HTH,
Phill W.
Nov 30 '06 #7
"Tomasz Jastrzebski" <oe****@nospam.nospamschrieb:
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?
The VB compiler doesn't perform such ugly method name matching to check if
an interface gets implemented. Instead, the 'Implements' keyword is used to
connect a method to a method of an interface it implements, which is a
cleaner approach. As an additional benefit this allows to choose more
meaningful names for the implemented members than those defined in the
interface. Check out the discussion below on how to archive behavior
similar to C#'s implicit interface implementation in VB:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/97a686e3f36ba978>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 30 '06 #8
Ha ha, you made my day.
Thank you!
"Master Programmer" <ma***************@outgun.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
>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:
>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...
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...
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

Nov 30 '06 #9
On 29 Nov 2006 20:30:42 -0800, "Master Programmer" <ma***************@outgun.comwrote:

¤ 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@

Since you seem to have a keen interest in the next version of Visual Basic 9.0 (Orcas) you may want
to download the CTPs.

http://msdn2.microsoft.com/en-us/library/aa463382.aspx

If you have questions feel free to post. I'm sure we would be more than willing to help you out. ;-)
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 30 '06 #10


"Master Programmer" <ma***************@outgun.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
>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

I usually don't respond to flamers but came across this website. MASTER
PROGRAMMER, this is for you:

http://amasci.com/weird/flamer.html

Now we know what's wrong with you. It is a mental disorder. There is a
good plan freely available to help you deal with your flaming/spamming
problem...it's a 3 step program. Mature, grow up, mature.

HTH,
Mythran
Nov 30 '06 #11
it IS being dropped

what would you know about programming; go and play with your titties,
sissy-pants

-Aaron

RobinS wrote:
Ignore him, he's wrong. VB is not going to be dropped.
Robin S.
-----------------------------
"Master Programmer" <ma***************@outgun.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
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:
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...
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...
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

Nov 30 '06 #12
There you go, making assumptions again.

Robin S.
-----------------------------
<aa*********@gmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
it IS being dropped

what would you know about programming; go and play with your titties,
sissy-pants

-Aaron

RobinS wrote:
>Ignore him, he's wrong. VB is not going to be dropped.
Robin S.
-----------------------------
"Master Programmer" <ma***************@outgun.comwrote in message
news:11**********************@j44g2000cwa.googleg roups.com...
>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:
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...
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...
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


Nov 30 '06 #13
hey you're the one with the sissy-pants name

im not making assumptions

-Aaron
RobinS wrote:
There you go, making assumptions again.

Robin S.
-----------------------------
<aa*********@gmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
it IS being dropped

what would you know about programming; go and play with your titties,
sissy-pants

-Aaron

RobinS wrote:
Ignore him, he's wrong. VB is not going to be dropped.
Robin S.
-----------------------------
"Master Programmer" <ma***************@outgun.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
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:
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...
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...
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


Nov 30 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kelly | last post by:
Hi, Sorry for this dumb question. Is there a difference between VB language and VB scripting? I need to buy a beginners VB scripting book, I just don't want to pickup the wrong one. Thanks.
17
by: Jared | last post by:
This is going to seem like a generic question that has been posed 1001 times and is probably very subjective, but I need some real world answers, rather than textbook answers. Let me give my...
8
by: Frank Buss | last post by:
A new challenge: http://www.frank-buss.de/marsrescue/index.html Have fun! Now you can win real prices. -- Frank Buß, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
8
by: ToM_tOm | last post by:
I've been programming in C++ for a few years now. At one stage, I had a great deal of it very fresh in my mind. About two weeks ago, I started back programming in C++ having not been at it for...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
22
by: Matt | last post by:
Some people identify Microsoft C# is Proprietary programming language. What is Proprietary programming language then? How does it differ from other languages such as C++, or Java?? Please...
0
by: richard | last post by:
The date for the second PyWeek challenge has been set: Sunday 26th March to Sunday 2nd April (00:00UTC to 00:00UTC). The PyWeek challenge invites entrants to write a game in one week from...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
84
by: aarklon | last post by:
Hi all, I found an interesting article here:- http://en.wikipedia.org/wiki/Criticism_of_the_C_programming_language well what do you guys think of this article....??? Is it constructive...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.