A constructor will make it more arranged and readable:
struct a
{
int x;
int y;
byte[] z;
public a(int xv, int yv, byte[] zv)
{
x = xv;
y = yv;
z = zv;
}
}
public void Initialize()
{
var b = new a[] {new a(0,0,new byte[] { 0,0,0}),
new a(1,1,new byte[] { 1,1,2})};
}
Another way According to your Comment
1. if you declare the access modifier of the struct fields as public you
will be able to initialize them using object initializer and not
with constructor (constructor is a method).
2. you can use static class and immediately call that object
3. make b
global and public (var is only local keyword) in order to call it
from outside (i would use a more descriptive name then b
).
full example:
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("y value of index 1 is: {0}", General.b[1].y);
Console.ReadLine();
}
}
public static class General
{
public static a[] b = new a[] { new a() { x = 0, y = 0, z = new byte[] { 0, 0, 0 }},
new a() { x = 1, y = 1, z = new byte[] { 1, 1, 1 }}
};
public struct a
{
public int x;
public int y;
public byte[] z;
}
}