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
Stephany Young - 29 Nov 2006 23:36 GMT
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.
> Hello,
>
[quoted text clipped - 53 lines]
> Sub m1()
> End Interface
thomas - 30 Nov 2006 03:01 GMT
The problem seems to be quite obvious.
What I am looking for is a *solution* - this newsgroup might be a better
place.
Tomasz
> Why have you bothered?
>
[quoted text clipped - 60 lines]
>> Sub m1()
>> End Interface
Master Programmer - 30 Nov 2006 04:30 GMT
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
> The problem seems to be quite obvious.
> What I am looking for is a *solution* - this newsgroup might be a better
[quoted text clipped - 65 lines]
> >> Sub m1()
> >> End Interface
RobinS - 30 Nov 2006 07:48 GMT
Ignore him, he's wrong. VB is not going to be dropped.
Robin S.
-----------------------------
>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
[quoted text clipped - 78 lines]
>> >> Sub m1()
>> >> End Interface
aaron.kempf@gmail.com - 30 Nov 2006 19:47 GMT
it IS being dropped
what would you know about programming; go and play with your titties,
sissy-pants
-Aaron
> Ignore him, he's wrong. VB is not going to be dropped.
> Robin S.
[quoted text clipped - 81 lines]
> >> >> Sub m1()
> >> >> End Interface
RobinS - 30 Nov 2006 21:55 GMT
There you go, making assumptions again.
Robin S.
-----------------------------
> it IS being dropped
>
[quoted text clipped - 94 lines]
>> >> >> Sub m1()
>> >> >> End Interface
aaron.kempf@gmail.com - 30 Nov 2006 23:07 GMT
hey you're the one with the sissy-pants name
im not making assumptions
-Aaron
> There you go, making assumptions again.
>
[quoted text clipped - 98 lines]
> >> >> >> Sub m1()
> >> >> >> End Interface
Herfried K. Wagner [MVP] - 30 Nov 2006 11:22 GMT
"Master Programmer" <master_programmer@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.

Signature
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
thomas - 30 Nov 2006 16:12 GMT
Ha ha, you made my day.
Thank you!
>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
[quoted text clipped - 78 lines]
>> >> Sub m1()
>> >> End Interface
Paul Clement - 30 Nov 2006 16:22 GMT
¤ 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)
Mythran - 30 Nov 2006 19:22 GMT
>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
Phill W. - 30 Nov 2006 12:01 GMT
> 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()
[quoted text clipped - 4 lines]
> Inherits c1
> Implements i1
Public Overrides Sub m1() Implements i1.m1
> End Class
HTH,
Phill W.
Herfried K. Wagner [MVP] - 30 Nov 2006 13:17 GMT
"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
[quoted text clipped - 4 lines]
> 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/97a686e3f
36ba978>

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