Spintz

If I have structures within structures, is there any way to allocate them when the "parent" structure is created

For example -

struct S1

{

int i1;
};

struct S2

{

int i2;

};

struct S

{

S1 s1;

S2 s2;
};

I just want to do - S myS = new S();

But I get errors. I end up marshalling data into the structure, so the data is there, but C# doesn't know about it, because it thinks s1 and s2 are null. Please don't tell me I have to do this -

S myS = new S();

myS.s1 = new S1();

myS.s2 = new S2();

- everytime I create a structure, please, tell this isn't so...



Re: .NET Base Class Library Complex Datatypes in structures

nobugz

Well, there's good news and bad news. Good news first: a struct is a value type, there's no reason to use "new" on a value type, other than keeping the compiler complaining about an uninitialized value. The V2.0 C# compiler has issues with that. Now the bad news: you're not close to identifying your marshaling problem. Nor are we, we should see the P/Invoke declaration before we could have half a clue.





Re: .NET Base Class Library Complex Datatypes in structures

Feng Chen - MSFT

Hi Spintz,


We are changing the issue type to ¡°Comment¡± because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to ¡°Question¡± by editing your initial post and changing the radio button at the top of the post editor window. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Thank you!






Re: .NET Base Class Library Complex Datatypes in structures

Spintz

Forget it. Structures are like a half-breed hybrid( more like *** step-child ) of C structures and C++ structures and are badly implemented in .NET. I will not be using them.