M
Mark Broadbent
Is it only really a good idea to use a struct when all the struct data
contains value types? I was writing one which used and exposed a public
string array property but there are a couple of things with this.
i. I am guessing the string array held within the struct would still be
stored in the heap anyway.
ii. I have noticed that the struct must be initialised using the
constructor to set the public values since if I simply declare and set
each property seperatly, the compiler complains that the struct is
uninitialised.
e.g.
Page p; //Page is a simple struct
string[] s = {"one", "two", "three"};
p.ID = 1; // compiler states p is unassigned
p.Attributes = s;
I cannot see the point to struct in this instance where public reference
types are used since the struct is less flexible. The following compiles..
string[] s = {"one", "two", "three"};
Page p = new Page(1, s);
p.ID = 1; // I can now set the properties without compiler problem
p.Attributes = s;
What do you all think?
Br,
Mark.
contains value types? I was writing one which used and exposed a public
string array property but there are a couple of things with this.
i. I am guessing the string array held within the struct would still be
stored in the heap anyway.
ii. I have noticed that the struct must be initialised using the
constructor to set the public values since if I simply declare and set
each property seperatly, the compiler complains that the struct is
uninitialised.
e.g.
Page p; //Page is a simple struct
string[] s = {"one", "two", "three"};
p.ID = 1; // compiler states p is unassigned
p.Attributes = s;
I cannot see the point to struct in this instance where public reference
types are used since the struct is less flexible. The following compiles..
string[] s = {"one", "two", "three"};
Page p = new Page(1, s);
p.ID = 1; // I can now set the properties without compiler problem
p.Attributes = s;
What do you all think?
Br,
Mark.