joebohen
joebohen

Reputation: 143

Call a c# parameterized Function from vb.net

I have a vb.net app that I want to use to make a call to a c# function that has a collection of class objects as a parameter. I have tried constructing a class with the same structure in the vb.net app and declaring a list of objects populating them with data and passing these into the c# class but I get a conversation error

List(of AddressClass) cannot be converted to List(Of AddressClass)

Is it possible to achieve this? If so, then how?

The function is:

public static string callMain(List<AddressClass[]> Addresses)
{
    // code.......
}

Upvotes: 1

Views: 120

Answers (1)

ADyson
ADyson

Reputation: 61894

You don't need to duplicate any classes. The whole beauty of the .NET Framework is the interchangeability of the languages. Just use the AddressClass definition which is used by the C# function. If the C# project is references in the VB one then your VB Code will recognise it.

So e.g. if the C# project's namespace is My.CSharp.Project then in VB you can just Dim list As new List(Of My.CSharp.Project.AddressClass).

Basically just treat the C# classes just like any other library. You don't know or care what language the System.IO classes are written in, do you? You just use them. The same goes for your C# project. In fact if you'd compiled your C# project to a DLL and manually imported it into your VB.NET project, you wouldn't even necessarily know it was a C# project - all you've got at that time is a compiled binary file.

Upvotes: 1

Related Questions