- Home /
Question by
Jimbow-Zheng · Dec 08, 2016 at 06:28 AM ·
c#unity 5constructorclass objectinitializer
C sharp Initializer not work in boolean member
Hello Community , I found something wierd : Class initializer not work in boolean members .
public class Test : MonoBehaviour {
void Start () {
var foo=new Foo(){Boolean=false,IntNumber=20,Str="Initialized string",Byte=20};
Debug.LogFormat("{0} {1} {2} {3}",foo.Boolean,foo.IntNumber,foo.Str,foo.Byte);
foo.Boolean=false;
Debug.Log(foo.Boolean);
}
class Foo{
public bool Boolean=true;
public byte Byte=10;
public int IntNumber=10;
public string Str="Default string";
public Foo(){
Debug.LogFormat("{0} {1} {2} {3}",Boolean,IntNumber,Str,Byte);
}
}
}
then it prints :
foo.Boolean
should be
1. True
in constructor , then
2. False
after initializer , and
3. False
when I set foo.Boolean=false;
But it remains True
in 2nd. step while other type members , like string
or byte
, work as my expection , and I don't know why .
Here is my enviroments below : Unity 5.1.5 / MonoDevelop-Unity 4.0.1
螢幕截圖-2016-12-08-135128.png
(35.4 kB)
Comment
24-hour courtesy bump, because this looks kinda strange.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity Network Player Classes, different models 1 Answer
How can I read an XML file in Android ? I can't access it 1 Answer