|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB vs. C# language challenge questionBelow 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 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 > 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 >> > > 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 > >> > > > > 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 >> >> >> > >> > > "Master Programmer" <master_program***@outgun.com> schrieb: Which is again complete nonsense.>I would just avoid VB all together, its about to be dropped from Visual > Studio in the next release. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> 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 >> >> >> > >> > > 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) "Master Programmer" <master_program***@outgun.com> wrote in message I usually don't respond to flamers but came across this website. MASTER 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 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 Tomasz Jastrzebski wrote:
> the VB.Net version does not compile due to the compiler error "non-explicitly implemented in the base class"> 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? 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 Overrides Sub m1() Implements i1.m1> Public Overridable Sub m1() > End Sub > End Class > > Class c2 > Inherits c1 > Implements i1 > End Class HTH,Phill W. "Tomasz Jastrzebski" <oegweb@nospam.nospam> schrieb: The VB compiler doesn't perform such ugly method name matching to check if > 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? 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/>
Full Screen
connect vb app to sql 2005 express How do you translate your WinForms app? (outsourcing localization) how to make cookies into an array? Looking for a simple explanation of how to walk through a dataset in .net 2.0 edit text in file using streamreader and string.replace Can't Figure Out why this array is out of bounds now! Delete Selected Lines from Text File loading treeview dynamically is very slow Add a META line to an existing HTML doc programmatically |
|||||||||||||||||||||||