Cannot implicitly convert type 'void' to 'int'?

前端 未结 3 1846
深忆病人
深忆病人 2021-01-16 11:32

Oke so I am fairly new to programming and I don\'t get why I get this error.

My method should store mails which it does in this method:

    public vo         


        
3条回答
  •  有刺的猬
    2021-01-16 12:23

    When making a method you define a return type. Void means it will not return anything. You have defined your method as public void StoreMail(), thus saying it will not return anything. When you call the method you ask for a return phishingMailId = _storageAgent.StoreMail(phishingMail). but because you defined the method as a void and you did not let the method return anything you can't get the id and you get the error.

    To fix this you will have to make your method return an int

    public int StoreMail(PhishingMail phishingMail){}
    

    then further in the method you define what you want to return

    return newId;
    

提交回复
热议问题