Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are strings stored in an object array?

object[] objs = new object[]{"one","two","three"};

Are the strings stored in the array as references to the string objects

[@] - one
[@] - two
[@] - three

or are the string objects stored in the array elements?

[one][two][three]

Thanks.

Edit: Sorry, my fancy diagram failed miserably.

like image 441
user943870 Avatar asked Feb 08 '26 05:02

user943870


1 Answers

String objects can never be stored directly in an array, or as any other variable. It's always references, even in a simple case such as:

string x = "foo";

Here the value of x is a reference, not an object. No expression value is ever an object - it's always either a reference, a value type value, or a pointer.

like image 122
Jon Skeet Avatar answered Feb 09 '26 19:02

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!