I have a class like this:
class MyClass { public object[] Values; }
Somewhere else I'm using it:
MyClass myInstance = new MyClass() {Values = new object[]{"S", 5, true}};
List<Func<MyClass, object>> maps = new List<Func<MyClass, object>>();
for (int i = 0; i < myInstance.Values.Length ; i++)
{
maps.Add(obj => obj.Values[i]);
}
var result = maps[0](myInstance); //Exception: Index outside the bounds of the array
I thought it will returns S
, but it throw exception. Any idea what is going on?
i
value is acting like reference values? – Incurve