I'm a little confused about this simply things. How Can I override vb.net Function in C#. I wrote this code in vb.net in vb.net class:
Public Overridable Function Test1() As Integer
Dim t1 As Integer
Return t1
End Function
I want to override this in C# class which inherits through vb.net class. Method code below.
public override int Test1()
{
int t1 = 2;
return t1;
}
I receive error: No suitable method to override.
I just tested this and it seems to work. My code:
Public Class TestClass
Public Overridable Function Test() As Integer
Dim t1 as Integer
Return t1
End Function
End Class
C#:
using MyVBProject;
public class CSharpClass : TestClass
{
public override int Test()
{
int t1 = 2;
return t1;
}
}
some things to check:
using
the vb namespace CSharpClass : TestClass
That can be because to put a public override, all class has to be public, instead, you can try to write "protected override" and not "public override". Otherwise, I think your question is alredy in stack overflow: link to question
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.