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

前端 未结 3 1851
深忆病人
深忆病人 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 11:57

    The method

    public void StoreMail(PhishingMail PhishingMail)

    is not returning any value. So when you do:

    phishingMailId = _storageAgent.StoreMail(phishingMail);

    You are getting that error, since StoreMail is declared as void, which means it does not return anything.

    To fix this, simply call StoreMail like this:

    _storageAgent.StoreMail(phishingMail);

    If you intend to return a value from StoreMail, then you must change it to return an int value:

    public int StoreMail(PhishingMail PhishingMail)
    {
        using (var phishingMailStorage = new PhishFinderModel())
        {
            phishingMailStorage.PhishingMail.Attach(PhishingMail);
    
            phishingMailStorage.SaveChanges();
        }
    
        return someIdWhichYouNeedToFigureOut;
    }
    

提交回复
热议问题