【发布时间】:2010-12-05 08:32:26
【问题描述】:
当我在 int 或 DateTime 属性上调用 GetType 时, 我得到了预期的结果,但是在字符串属性上, 我得到一个 NullReferenceException (?):
private int PropInt { get; set; }
private DateTime PropDate { get; set; }
private string propString { get; set; }
WriteLine(PropInt.GetType().ToString()); // Result : System.Int32
WriteLine(PropDate.GetType().ToString()); // Result : System.DateTime
WriteLine(propString.GetType().ToString()); // Result : NullReferenceException (?!)
有人能解释一下是怎么回事吗? string-prop 和 int-prop 有什么不同?
【问题讨论】:
标签: c# properties nullreferenceexception gettype