Home All Groups Group Topic Archive Search About

VB vs. C# language challenge question

Author
29 Nov 2006 11:28 PM
Tomasz Jastrzebski
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

Author
29 Nov 2006 11:36 PM
Stephany Young
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.


Show quoteHide quote
"Tomasz Jastrzebski" <oegweb@nospam.nospam> wrote in message
news:Ojor$3AFHHA.2452@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
>
Author
30 Nov 2006 3:01 AM
thomas
The problem seems to be quite obvious.
What I am looking for is a *solution* - this newsgroup might be a better
place.
Tomasz

Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:OX40n8AFHHA.1216@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" <oegweb@nospam.nospam> wrote in message
> news:Ojor$3AFHHA.2452@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
>>
>
>
Author
30 Nov 2006 4:30 AM
Master Programmer
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:
Show quoteHide quote
> 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@localhost> wrote in message
> news:OX40n8AFHHA.1216@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" <oegweb@nospam.nospam> wrote in message
> > news:Ojor$3AFHHA.2452@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
> >>
> >
> >
Author
30 Nov 2006 7:48 AM
RobinS
Ignore him, he's wrong. VB is not going to be dropped.
Robin S.
-----------------------------
Show quoteHide quote
"Master Programmer" <master_program***@outgun.com> wrote in message
news:1164861042.245149.262030@j44g2000cwa.googlegroups.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@localhost> wrote in message
>> news:OX40n8AFHHA.1216@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" <oegweb@nospam.nospam> wrote in message
>> > news:Ojor$3AFHHA.2452@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
>> >>
>> >
>> >
>
Author
30 Nov 2006 11:22 AM
Herfried K. Wagner [MVP]
"Master Programmer" <master_program***@outgun.com> schrieb:
>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/>
Author
30 Nov 2006 4:12 PM
thomas
Ha ha, you made my day.
Thank you!


Show quoteHide quote
"Master Programmer" <master_program***@outgun.com> wrote in message
news:1164861042.245149.262030@j44g2000cwa.googlegroups.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@localhost> wrote in message
>> news:OX40n8AFHHA.1216@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" <oegweb@nospam.nospam> wrote in message
>> > news:Ojor$3AFHHA.2452@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
>> >>
>> >
>> >
>
Author
30 Nov 2006 4:22 PM
Paul Clement
On 29 Nov 2006 20:30:42 -0800, "Master Programmer" <master_program***@outgun.com> wrote:

¤ 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)
Author
30 Nov 2006 7:22 PM
Mythran
"Master Programmer" <master_program***@outgun.com> wrote in message
news:1164861042.245149.262030@j44g2000cwa.googlegroups.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
Author
30 Nov 2006 12:01 PM
Phill W.
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.
Author
30 Nov 2006 1:17 PM
Herfried K. Wagner [MVP]
"Tomasz Jastrzebski" <oegweb@nospam.nospam> schrieb:
> 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/>