I am trying to create a 2d array but I don't seem to be able to pass a value in the constructor.
For example
public class MyObj
{
public string State {get; private set;}
public MyObj(string s)
{
this.State = s;
}
}
And in another class
private MyObj[,] Obj;
private void Setup()
{
this.Obj = new MyObj[5,5];
}
When I review this.Obj the value of State is always null. I understand why but without looping over each item in the array (after it's created) and setting the State property (removing the private set) I'm not sure if I have other options?
Whilst I know the syntax is wrong, something like
this.Obj = new MyObj("default text for each item in array")[5,5,]
public MyObj(string s) { State = string.IsNullOrEmpty(s) ? "default value" : s;}?