using System;
namespace Test
{
class Test
{
public bool A = true;
}
class Program
{
static void Main(string[] args)
{
var test = new Test
{
A = false
};
Console.WriteLine("test.A = " + test.A);
}
}
}
When I compile this C# code into a Visual Studio console executable, I get: "test.A = False". However, in Unity 3.3.0f4 (after I delete the namespace bit and change Console.WriteLine to Debug.Log) I get: "test.A = True"
My question: is this a bug in Mono? (I'd expect the VS behaviour)
Looks like a mono bug, if you use properties instead of public fields it works fine:
using UnityEngine;
public class TestBug : MonoBehaviour
{
void Start()
{
var test = new Testee()
{
A = false
};
Debug.Log("test.A = " + test.A); // Prints False, as expected.
}
}
class Testee
{
private bool a = true;
public bool A { get { return a; } set { a = value; } }
}
Indeed, I get the same strange behavior in Unity3D.
using UnityEngine;
public class Test : MonoBehaviour
{
void Start()
{
var test = new Testee()
{
A = false
};
Debug.Log("test.A = " + test.A); // Prints True, not False as expected.
}
}
class Testee
{
public bool A = true;
}
...And the behavior in a VS Console App prints False, not True.
I haven't got the slightest clue what Mike was talking about, but it sounds like a bug to me.