I have an array of structures in one C# class and I want to pass that data into another class.
Here is my code
private struct strClassOfService { public string COS; public string myValue; } private strClassOfService[] arrCOS = null; // // some code that loads arrCOS with data // // // here is where i will instantiate another class and // set the arrCOS so I can use it in the other class //
If all else fails I suppose I could reload the data in the other class. But I am curious if there is a way. So far my attempts have failed.
Well, for one thing, if you intend to pass the structure to another class, you ought to make the structure definition public (or at least internal)… once you do that, you can use all sorts of methods (properties, method calls, etc) to copy the data over to your other class.
Two techniques are shown below (of course, you’d only need to use one…)