No, the value isn't copied - arr[i]
is classified as a variable, so Baz
will be fetched "in place". It took me a while to work out how you could validate that, but it is just about possible, by making the property change the value in the array...
using System;
public struct Foo
{
private int field;
public int Value
{
get
{
Test.array[0].field = 10;
return field;
}
}
}
public class Test
{
public static Foo[] array = new Foo[1];
static void Main()
{
Console.WriteLine(array[0].Value); // Prints 10
}
}
Note that your comment about "the Foo obj" is somewhat misleading in C# - there isn't an object here; there's just a value of type Foo
.