Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#是否调用反序列化构造函数而不是默认构造函数?_C#_Wpf_Serialization_Constructor_Iserializable - Fatal编程技术网

C#是否调用反序列化构造函数而不是默认构造函数?

C#是否调用反序列化构造函数而不是默认构造函数?,c#,wpf,serialization,constructor,iserializable,C#,Wpf,Serialization,Constructor,Iserializable,我刚刚开始熟悉C#中对象的序列化。我想知道是否调用了反序列化构造函数而不是默认构造函数,或者是除了。如果是附加的,这些调用的顺序是什么?例如: [Serializable()] public class ReadCache : ISerializable { protected ArrayList notifiedURLs; // Default constructor public ReadCache() { notifiedURLs = ne

我刚刚开始熟悉C#中对象的序列化。我想知道是否调用了反序列化构造函数而不是默认构造函数,或者是除了。如果是附加的,这些调用的顺序是什么?例如:

[Serializable()]
public class ReadCache : ISerializable
{
    protected ArrayList notifiedURLs;

    // Default constructor
    public ReadCache()
    {
        notifiedURLs = new ArrayList();
    }

    // Deserialization constructor.
    public ReadCache(SerializationInfo info, StreamingContext ctxt)
    {
        //Get the values from info and assign them to the appropriate properties
        notifiedURLs = (ArrayList)info.GetValue("notifiedURLs", typeof(ArrayList));
    }
}
不,它将被称为“代替”,而不是默认值-但您可以使用以下内容初始化列表:

public ReadCache(SerializationInfo info, StreamingContext ctxt)
  : this()
{
    //Get the values from info and assign them to the appropriate properties
    notifiedURLs = (ArrayList)info.GetValue("notifiedURLs", typeof(ArrayList));
}
请注意“…:this()”语法-但在您的特殊情况下,您不必这样做

明白了。使用:this()时,首先执行哪个代码?默认构造函数代码还是反序列化构造函数代码?您的“默认”-构造函数-中的部分请仔细想想,否则不是很有用,不是吗?