I am trying to understand what is going on behind the curtain when I create an array with a constant size as below:
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public float[] constArray;
I understand that I can use the fixed
key word, but then ref
is no longer an options, and all pointer operations must be inside a fixed expression.
What I am trying to do is parse an XML file and store at an given index in the array. So if there are 10 elements in the file I might set up the following:
for (int i = 0; i < 10; i++)
{
readElement("element", ref constArray[i]);
}
However, constArray[i]
is null
.
Maybe a further instantiation is require, but then what is the point of marshalling. I thought marshalling created the object that ref
operates on to create a reference.
I read through reference types and value types with out finding much information. I also read a few others such as ref and referencing arrays with out much progress.
I just can seem to find a resource that provides a good conceptual understanding. So any resources, as well as an answer, would be greatly appreciated.
Thank you, Blake