S
Steve Roberts
In C# is it possible to initialize the items of an array when the array is
an array of structures?
When I try to initialize the items of the array (as shown below) using the
method I would use in C++, I get the compiler error "Array initializers can
only be used in a variable or field initializer. Try using a new expression
instead.":
Is there a way to do this?
Thanks for any help,
Steve
public struct test
{
public int id;
public string name;
}
public test[] testArray = { {1,"name1"}, {2,"name2"} };
an array of structures?
When I try to initialize the items of the array (as shown below) using the
method I would use in C++, I get the compiler error "Array initializers can
only be used in a variable or field initializer. Try using a new expression
instead.":
Is there a way to do this?
Thanks for any help,
Steve
public struct test
{
public int id;
public string name;
}
public test[] testArray = { {1,"name1"}, {2,"name2"} };