Question by
SuperUltraHyper · Sep 14, 2015 at 04:48 PM ·
c#arrayclass object
How to modify a 2d array [,] of a class?
I have a Class that looks like:
public class ProcessorSlotDetails {
public GameObject button;
public string slotType;
public int testInt;
public int[] positiveOutDirection;
public int[] negitiveOutDirection;
public int[,] enterDirections;
}
public class ProcessorDetails {
public int processorColumnsSlots;
public int processorRowSlots;
public ProcessorSlotDetails[,] processorSlotDetails;
}
and I am trying to addess variable inside but I can't figure out what will work:
processorDetails.processorSlotDetails[1,1].slotType = "new";
//or
processorDetails.processorSlotDetails.slotType.SetValue( "new", 1,1)
Any Idea what I an doing wrong?
Thanks!
Comment
Answer by hexagonius · Sep 14, 2015 at 05:31 PM
This might help:
I looked at that before I wrote this. It basic say to do this and it doesn't work. array5[2, 1] = 25; or processorDetails.processorSlotDetails[1,1].slotType = "text"; I get: "NullReferenceException: Object reference not set to an instance of an object"
first, you need to initialize the whole thing to a certain length. an array can't be accessed without elements.
array5 = new int[10,10];