Today I encountered some behavior that was unexpected, at least to me, while using object initializers in C#.
Example A
public class Foo {
public bool Bar = false;
}
PassInFoo( new Foo { Bar = true } );
Example B
public class Foo {
public bool Bar = true;
}
PassInFoo( new Foo { Bar = false } );
Example A works as I'd expect. The object passed into PassInFoo has Bar set to true. However, in Example B, foo.Bar is set to true, despite being assigned false in the object initializer. What would be causing the object initializer in Example B to be seemingly ignored?
Note: this problem does not reproduce in a Visual Studio C# console project, so it appears to be Unity or MonoDevelop specific.
Didn't find that when I searched /sheepish
– nschrag