문제

C #에서 물체의 직렬화에 익숙해지고 있습니다.Deserialization 생성자가 기본 생성자 대신 또는 추가로 호출되는지 궁금합니다.그 외에도, 이들은 어떤 순서가 무엇입니까?예 :

[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));
}
.

" ... :이 () "- 구문 -하지만 특별한 경우에는 필요하지 않습니다!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top