I am working with a project and I got stucked, I want to create an array of a class, this class contains two int fields, I want to create an instance with Array.CreateInstance(), this method creates correctly an array with the correct length but instead of giving access to the int variables, the array is initialize as an array of null.
This is a simulation, the name of the class ProcessFaults is read during runtime with the reflection.
public class ProcessFaults
{
public int _class;
public int _group;
public ProcessFaults()
{
}
}
class Program
{
static void Main(string[] args)
{
object activatorTest = Activator.CreateInstance(typeof(Container));
FieldInfo arrayFieldInfoInsideClass = Type.GetType("Testing_Reflection.Container").GetField("_dataProcessFaults", BindingFlags.Instance | BindingFlags.Public);
Type arrayTypeInsideClass = arrayFieldInfoInsideClass.FieldType;
FieldInfo elementClassInsideArray = arrayTypeInsideClass.GetElementType().GetField("_class", BindingFlags.Instance | BindingFlags.Public);
Array a = Array.CreateInstance(arrayTypeInsideClass, 10);
}
}
that Produces following Output:
- Is there any form to initialize correctly the array?
- Is there any form to write directly to the variable _class and _group?
Regards!

var arr = (ProcessTypes[])a;then initialisearr[]in a loop as you would a normal array.