tags:

views:

391

answers:

1

I have a C++ list which contains a struct. My C++/CLI project consumes the native C++. I would like to return a managed list to my C# project. How can I convert my C++ list into a managed list?

+2  A: 

First you need a ref class that acts as a wrapper around the struct for each item. You can store a pointer to the struct as a field in the ref class. Let's call it StructWrapper.

Then you need something to represent the list. The most flexible way to do that is to expose an IEnumerable<StructWrapper>. Either write your own implementation (not as bad as it sounds) or just load all the items into a List<StructWrapper> and return that.

Daniel Earwicker