Waqar Malik Waqar Malik - 2 months ago 5
ASP.NET (C#) Question

Why am I getting error in this term expression?

I have a error message when I hover over this line


"An object reference is required for the non static field, method or
property 'SmtpClient.send(mailMessage)'


SmtpClient smtpClient = new SmtpClient();
SmtpClient.Send(mailMessage); //Error over this line

Answer

You're referencing the class, not your variable.

SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(mailMessage); 

This will fix it.