473,765 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.publi c.dotnet.framew ork,
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 2360
Why have you bothered?

Your earlier identical post has been discussed in
microsoft.publi c.dotnet.framew ork some hours ago., and the responses there
were both correct and explained the situation comprehensively .
"Tomasz Jastrzebski" <oe****@nospam. nospamwrote in message
news:Oj******** ******@TK2MSFTN GP06.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.publi c.dotnet.framew ork, 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@localhos twrote in message
news:OX******** ******@TK2MSFTN GP05.phx.gbl...
Why have you bothered?

Your earlier identical post has been discussed in
microsoft.publi c.dotnet.framew ork some hours ago., and the responses there
were both correct and explained the situation comprehensively .
"Tomasz Jastrzebski" <oe****@nospam. nospamwrote in message
news:Oj******** ******@TK2MSFTN GP06.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.publ ic.dotnet.frame work, 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@localhos twrote in message
news:OX******** ******@TK2MSFTN GP05.phx.gbl...
Why have you bothered?

Your earlier identical post has been discussed in
microsoft.publi c.dotnet.framew ork some hours ago., and the responses there
were both correct and explained the situation comprehensively .
"Tomasz Jastrzebski" <oe****@nospam. nospamwrote in message
news:Oj******** ******@TK2MSFTN GP06.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.publi c.dotnet.framew ork, 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.comw rote in message
news:11******** **************@ j44g2000cwa.goo glegroups.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@localhos twrote in message
news:OX******* *******@TK2MSFT NGP05.phx.gbl.. .
Why have you bothered?

Your earlier identical post has been discussed in
microsoft.publi c.dotnet.framew ork some hours ago., and the responses
there
were both correct and explained the situation comprehensively .
"Tomasz Jastrzebski" <oe****@nospam. nospamwrote in message
news:Oj******** ******@TK2MSFTN GP06.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.publ ic.dotnet.frame work, 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.coms chrieb:
>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.d e/group/microsoft.publi c.dotnet.langua ges.vb/msg/97a686e3f36ba97 8>

--
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.comw rote in message
news:11******** **************@ j44g2000cwa.goo glegroups.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@localhos twrote in message
news:OX******* *******@TK2MSFT NGP05.phx.gbl.. .
Why have you bothered?

Your earlier identical post has been discussed in
microsoft.publi c.dotnet.framew ork some hours ago., and the responses
there
were both correct and explained the situation comprehensively .
"Tomasz Jastrzebski" <oe****@nospam. nospamwrote in message
news:Oj******** ******@TK2MSFTN GP06.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.publ ic.dotnet.frame work, 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.comw rote:

¤ 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

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

Similar topics

2
2670
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
2908
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 background in 2-3 sentences: 1. I am a developer who has been programming for about 3 years and have done the following: - Java (1 year experience) - Visual Basic 6 (Done quite a few in house utility and add on programs)
8
1709
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
2794
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 maybe a year. I opened a few of my old source files and was... well... unfamiliar! Looking at "p_k = &k" and the like left me staring blankly at the screen trying to think exactly what that meant... ?
32
4655
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 where the loop will be traversed a fixed number of times. It is very flexible, and novice programmers should take care not to abuse the power it offers."
22
13712
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 advise. thanks!!
0
1234
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 scratch either as an individual or in a team. Entries must be developed in Python, during the challenge, and must incorporate some theme chosen at the start of the challenge. REGISTRATION IS NOW OPEN --
669
26183
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
84
8590
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 criticism that needs to be appreciated always...???
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.