Constructor cannot call itself c#

前端 未结 1 420
情书的邮戳
情书的邮戳 2021-01-23 23:37

Constructor \"Delay.vkMessages.vkMessages(string, System.DateTime, string, bool, string)\" cannot call itself.I have another class, copy of this class, but it works(I can add co

相关标签:
1条回答
  • 2021-01-24 00:03

    Remove the last parameter:

    public vkMessages(string kto, DateTime date_time,
                      string text, bool read_state,string in_or_out)
        : this(kto, date_time, text, read_state)
    {
        InOrOut = in_or_out;
    }
    

    That said, your logic is skewed, it should be the other way round (i.e. this constructor should do all the work and the other constructor should call this one:

    public vkMessages(string kto, DateTime date_time, string text, bool read_state)
        : this(kto, date_time, text, read_state, false) { }
    
    public vkMessages(string kto, DateTime date_time,
                      string text, bool read_state,string in_or_out)
    {
        InOrOut = in_or_out;
        Kto = kto;
        Date_Time = date_time;
        TexT = text;
        Read_State = read_state; 
    }
    

    Finally, you should fix your identifiers to conform to the .NET guidelines. In particular, a class should follow the PascalCase convention of starting with an upper-case letter.

    0 讨论(0)
提交回复
热议问题