Nikhil Agrawal Nikhil Agrawal -3 years ago 168
C# Question

How to create an interface method which when not implemented shows exception code in VB.Net, just like in C#

I have seen in C# that Interfaces when implemented in a class, give methods with an

NotImplementedException
block in them.

This way

public interface IDisposable
{
void Dispose();
}


and when implimenting it

public class Class1 : IDisposable
{
public void Dispose()
{
throw new NotImplementedException();
}
}


Now my question


  1. Is this only a C# built-in facility and is not available in VB.Net?

  2. If No, how can I have this functionality in VB.Net?


Answer Source

You can use a Visual Studio plug-in like JustCode, which offers such a feature for VB.Net:

Interface Foo
    Sub Bar()
End Interface

Class FooBar
    Implements Foo

    Public Sub Bar() Implements Foo.Bar     -+
        ' TODO: Implement this method        +-- these lines are autogenerated
        Throw New NotImplementedException()  |
    End Sub                                 -+

End Class
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download