是在补水时调用的对象构造函数
我有一个对象,在实例化时,它通过构造函数为其自身提供一个唯一的 id。我的问题可能很愚蠢,但我似乎找不到答案。
构造函数会在从隔离存储中重新水化时被调用吗?或者仅在使用“new”关键字时调用构造函数。我的意图不是让它被调用,因为我只想在第一次实例化时调用它。
I have an object that upon instantiation greats a unique id for itself via the constructor. My question may be silly but I cannot seem to find the answer.
Will the constructor be called upon rehydration from isolated storage? or is the constructor only called when using the 'new' keyword. My intention is not to have it called as I only want it to be called when instantiating for the first time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认构造函数将在反序列化过程中被调用。它将创建对象,然后复制序列化的属性/字段。
The default constructor will be called during the deserialization process. It will create the object and then copy over the serialized properties/fields.
尽管这是针对 .Net 4,而不是 Silverlight,根据 MSDN:ISerialized Interface,具体来说:
...我不希望 Windows Phone 上有什么不同。
Although this is for .Net 4, not Silverlight, according to MSDN: ISerializable Interface, specifically:
... I wouldn't expect anything different on the Windows Phone.