You should use Person[] instead of a list.
How to return a struct with a List in WRC c# to c++/WinRT
I have two structs, one contains a List<struct> which holds the other struct. How can I return this to C++/WinRT?
I know that something like a list would have an alternative for Windows Runtime Component use, I tried to use IVector, but it doesn't work due to it's protection level. None of the types that the error says are allowed for structs can contain multiple pieces of data, so I'm confused as to what is expected. Note, I don't need these to be structs, class or any alternative that would work better is fine.
// i have a method that returns Holders
public struct Holder {
...
List<Person> people;
...
}
public struct Person {
...
some code
...
}
2 answers
Sort by: Most helpful
-
-
JRH3221 0 Reputation points
2023-07-25T09:40:26.21+00:00 I figured it out.
Instead of using a struct, use a class, but all the variables have to be private, so you need to use a property rather than a field. An example of what it might look like:
sealed class Class1 { public Class2 Run() { // call this from c++ return new Class2(); } } public sealed class Class2 { // vars that you want to access private int iD; private IList<string> strings = new List<string>(); // the properties for those vars, use a different name, i recommend having the same name with different // starting case, lower for private, upper for public public int ID { get { return ID; } set { iD = value; } } public IList<string> Strings { get { return Strings; } set { strings = value; } } }