I want to set values to my struct written en C# and i'm getting one error.
private struct pack2
{
public float var;
public float [3]var2;
}
private struct pack
{
public pack2[] ster;
}
private void recv()
{
pack mystruct;
mystruct.ster = new pack2[4]; // Because I need to declare 4 structures of pack2
mystruct.ster[0].var = 2F;
mystruct.ster[0].var[0] = 1F; // error
}
ERROR : NullReferenceException was unhandled , Addinfo : object reference not set to an instance of an object
how can I fix it?
SOLVED:
private struct pack2
{
public float var;
public float [3]var2;
}
private struct pack
{
public pack2[] ster;
}
private void recv()
{
pack mystruct;
mystruct.ster = new pack2[4]; // Because I need to declare 4 structures of pack2
mystruct.ster[0].var = 2F;
mystruct.ster[0].var2 = new float[3]; // Because I need 3 floats on each pack2
mystruct.ster[1].var2 = new float[3]; // Because I need 3 floats on each pack2
mystruct.ster[2].var2 = new float[3]; // Because I need 3 floats on each pack2
mystruct.ster[3].var2 = new float[3]; // Because I need 3 floats on each pack2
mystruct.ster[0].var2[0] = 1F;
mystruct.ster[0].var2[1] = 1F;
mystruct.ster[0].var2[2] = 1F;
}
I hope will be useful for people. Thanks to alex