Fork me on GitHub


[C#] the error "Object reference not set to an instance of an object"

會發生這個 error 的原因是: The code is trying to access a member of a reference type variable that is set to null.

當使用automatic properties 的時候,如果沒有初始化 value type 的 property 會是 0, reference type 則會是 null。因此在建構子當中要針對 properties 做初始化的動作 ( "new" )



No comments:

Post a Comment