views:

212

answers:

3

I can't get a handle on the syntax. Can anyone give me a simple demo?

+9  A: 

It's been awhile but I think it's just:

Class MyClass : Inherits MyBaseClass : Implements IMyInterface1, IMyInterface2

The : are just so you can do it all on one line. If you don't use them it looks like:

Class MyClass 
   Inherits MyBaseClass 
   Implements IMyInterface1, IMyInterface2

Which is confusing if you're looking at a C# example because in that the colon is the inherit operator.

Spencer Ruport
That's C#, the OP asked for VB.Net
TGnat
Note my explanation. ;)
Spencer Ruport
Thanks... Didn't know you could do that.
TGnat
+1  A: 

You cannot inherit implementations from more than one place in VB & C#, afaik. I guess you can do multiple Interface inheritance, though.

RBarryYoung
+1, but note it's "implement" when referring to interfaces, not "inherit"
Rex M
Rex M: Yes, that's the language's syntax, but the terminology is "interface inheritance" and implementation" inheritance" (http://en.wikipedia.org/wiki/Interface_inheritance). Or at least it was when I learned it (many years ago).
RBarryYoung
+3  A: 

In VB.NET a class can only inherit from one base class. A VB.Net class can implement multiple interfaces.

Inherits statement:

Public Class thisClass
    Inherits anotherClass
End Class

Implementing an interface:

Public Class thisClass
    Implements IComparable, IDisposable
End Class

Both Inheriting and implementing in VB.NET:

Public Class thisClass
    Inherits anotherClass
    Implements IComparable, IDisposable
End Class
Jeff Widmer
Technically, both of those things are "inheritance", though Microsoft encourages us to use different verbs for them.
RBarryYoung