I want to assign output values on Data class after create object with ref constructor to State class in this code. How can I solve this?
class Program
{
static void Main(string[] args)
{
Data data = new Data();
State stateA = new State("A", ref data.outputA);
State stateB = new State("B", ref data.outputB);
stateA.output = 10;
stateB.output = 8;
Console.WriteLine(data.outputA); //10
Console.WriteLine(data.outputB); //8
Console.ReadLine();
}
}
public class Data
{
public int outputA;
public int outputB;
}
public class State
{
public string name;
public ref int address;
public State(string _name, ref int _output)
{
this.name = _name;
address = _output;
}
}