I have a solution with multiple projects, some of the projects are written in VB, some in C#. I am wondering if there’s a way to use interfaces and/or enums written in VB in C# classes? My C# code below doesn’t compile, however I am able to see the interface in intellisense.
VB Code:
Namespace A
Public Inteface IHandler
Function Handle() As HandlerResult
End Interface
Public Enum HandlerResult
Success = 1
Fail = 0
End Enum
End Namespace
C# Code:
using A;
namespace B
{
public class MyHandler : IHandler
{
public HandlerResult Handle(){
return HandlerResult.Success;
}
}
}
P.S It’s a console/service application, not ASP.Net (where I know it’s doable).
UPD: Sorry guys, was missing a reference to the project with the interface. It’s fixed now. I think the thing that in VB projects references are done slightly different than in C# confused me.
This will work if you put the C# code in a different assembly than the VB code. In order to avoid circular dependencies, you may have to move all of your existing VB code into a DLL assembly. That way you can reference the VB.Net assembly from your new C# assembly, and reference both assemblies from the main exe assembly.
Note that if you do this the namespace when viewed from C# will not be simply “A”, it will be nested below the default namespace of the VBProject, e.g.
In this example, the default namespace of the VB project I created was
StackOverflow7843509