How can I manipulate a VB6 Collection in .NET?

2019-05-14 13:35发布

问题:

I am currently in the process of designing an interface for .NET software that would be consumed by COM objects - specifically, VB6.

While I have found a number of pages by Microsoft detailing how to make an COM-interoperable interface, I am currently tripping over the use of Collections in design time: I would like to be able to use a standard VB6 "Collection object" in the .NET program - that way, I would be able to specify, in the interface, such a collection as an argument, or as a return type, simplifying the work required for clients to use the interface.

Thank you in advance.

Edit: I don't intend to use VB6 collections in the "real work" .NET program - I would convert the VB6 collections as soon as possible and call other methods using proper .NET collections.

回答1:

You shouldn't use a type such as the Collection Object from the Visual Basic Runtime in .NET.
Instead you should try to find an equivalent class in the System.Collections namespace that best suits your needs. Check out the following article for some guidance:

  • Using collections in .NET