简体   繁体   中英

How does C# manage uninitialized classes?

I am using C# in Unity and I need to know how does C# manages classes in order to know if I need to set all of the values during or after the new to avoid invalid reads or if I can leave them as they are.

With this example I get the following output :

class Test {
  public int test;
}
Test buffer = new Test;
Debug.Log(buffer.test);

0
UnityEngine.Debug:Log(Object)

Does this mean the variable types all have a default value or should I be more careful when instantiating a Class ?

.Net框架将所有字段初始化为其默认值( 0null )。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM