Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to define a collection of objects in C# that I can also use in VB6. I need the VB6 app to populate the collection and the C# app will then read the collection and use the data.

I have succesfully used simple classes in this way but want to do the same thing with collections.
Posted
Updated 25-May-16 12:41pm
Comments
Sergey Alexandrovich Kryukov 20-Mar-15 8:06am    
Forget VB6, this is the only non-nonsense thing you can do.
—SA
Phil McT 20-Mar-15 8:11am    
I'm trying to believe me!

I believe you can only use collection in vb.net instead of c#. C# has Collection, but you have to specify the type, for example Collection<yourclass>, and this structure cannot be used by VB6!
In vb.net, you can create a generic list with a property is Collection, then you can add any object to this collection and comsume it in VB6

VB.NET
Public Class GenericList
    Private _list As New Collection

    Public Property List() As Collection
        Get
            Return _list
        End Get
        Set(value As Collection)
            _list = value
        End Set
    End Property
End Class
 
Share this answer
 
This can be tried using interop - C# Com[^].
 
Share this answer
 
Comments
Phil McT 20-Mar-15 6:53am    
I've had a quick look but it doesn't look like that example deals specifically with collections, which is what I'm after. I can expose classes that use simple types like int, string, bool etc. But I want to use a collection and within VB add new items and enumerate it with For Each etc.
Dave Kreskowiak 25-May-16 19:05pm    
You're going to have to wrap the collection in a class and use COM-exposed methods in that class to manage the collection which VB6 will be able to call. You're not going to be able to use a .NET collection class directly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900