String Array in a struct
-
Hi, i want an string-array with a fixed size within a struct. How can I achieve this? The normal way to initialize the array doesn't work. Also using fixed is no solution because it does not support the type string (a string has no fixed size).
public struct Order
{
public string owner;
public string prognr;
public string number = new string[20];
}Thanks in advance
-
Hi, i want an string-array with a fixed size within a struct. How can I achieve this? The normal way to initialize the array doesn't work. Also using fixed is no solution because it does not support the type string (a string has no fixed size).
public struct Order
{
public string owner;
public string prognr;
public string number = new string[20];
}Thanks in advance
-
Hi, i want an string-array with a fixed size within a struct. How can I achieve this? The normal way to initialize the array doesn't work. Also using fixed is no solution because it does not support the type string (a string has no fixed size).
public struct Order
{
public string owner;
public string prognr;
public string number = new string[20];
}Thanks in advance
-
Hi Vikram, if I try this I get an error saying: Compiler Error CS0573 Error Message 'field declaration' : cannot have instance field initializers in structs So, obviously I can't initialize this array within the struct, but initializing the array out of the struct as:
Order or = new Order();
or.Number = new or.Number[20];is also not working.
-
Hi Vikram, if I try this I get an error saying: Compiler Error CS0573 Error Message 'field declaration' : cannot have instance field initializers in structs So, obviously I can't initialize this array within the struct, but initializing the array out of the struct as:
Order or = new Order();
or.Number = new or.Number[20];is also not working.
Create a default constructor that initialises the field.
JF2015 wrote:
or.Number = new or.Number[20];
That's never going to work, what do you expect it to do ? or.Number = new string[20]; assuming it's an array of strings, is what you need.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Create a default constructor that initialises the field.
JF2015 wrote:
or.Number = new or.Number[20];
That's never going to work, what do you expect it to do ? or.Number = new string[20]; assuming it's an array of strings, is what you need.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Ok, my fault, i originally thought that i had to initialize the array within the struct, but didn't know i had to do it like you wrote. Thanks alot
Glad to help :-)
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Ok, my fault, i originally thought that i had to initialize the array within the struct, but didn't know i had to do it like you wrote. Thanks alot