It's complicated. An array is a reference, but it's a reference to an array of references. And strings are a special case, because they are immutable: once created, they cannot be changed, so the following code doesn't necessarily do what you might think:
string x = "XXX";
string y = x;
x = "YYY";
Console.WriteLine("{0}:{1}", x, y);
This will print "YYY:XXX" because the immutability means that the string reference acts like a value - instead of changing the existing reference content, a new reference is created, so the old string is not affected at all.
When you run your code, you get a similar effect:
string[] strArr = GetNames();
returns a reference to an array of strings.
string[] strArr2 = GetNames();
Also returns a reference to an array of strings.
But ... they aren't the same reference, because it isn't the same array!
Try it:
if (strArr == strArr2) Console.WriteLine("Same");
else Console.WriteLine("Different");
Will always print "Different" because despite the strings being the same, the arrays are not.
Every time you execute this code:
string[] ret = { "Matthew", "Mark", "Luke", "John" };
The framework creates a new array, and fills it with the strings for you to return.
If you want to share them, you would need to return the same array:
static string[] ret = { "Matthew", "Mark", "Luke", "John" };
static string[] GetNames()
{
return ret;
}
Now, you will get
strArr[0] = Nik and strArr2[0] = Nik
And "Same" if you do the comparison.