如何在C#中使非值类型可以为空?

use*_*038 3 c# types reference

例如:

public class Stereo {
   public Speaker? LeftSpeaker;
   public int? Volume;
}
Run Code Online (Sandbox Code Playgroud)

int?精细的作品,但我不能让音箱空.这对谷歌来说实在是太难了,我觉得这很简单......

Nol*_*rin 13

你为什么要那样?可以设置非值类型(即引用类型)并与之进行比较null.

添加Nullable<T>过引用类型对象将创建包装2空性的层; 无意义的复杂性,因此是不允许的.