Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Member 'object.Equals(object, object)' cannot be accessed with an instance reference; qualify it with a type name instead

Tags:

c#

asp.net

When I used the following code in C#...

int totalValue = 0;
int total = 0;
totalValue = int.Parse(Session["price"].ToString()) * int.Parse(Session["day"].ToString());

// This line causes the error
totalValue += Session["IsChauffeurUsed"].ToString().Equals("Yes", StringComparer.CurrentCultureIgnoreCase) ? 80 : 0;

... I received this error :

Member 'object.Equals(object, object)' cannot be accessed with an instance reference; qualify it with a type name instead.

What does that error indicate?

like image 322
Stuck Avatar asked Aug 02 '12 07:08

Stuck


1 Answers

You are using wrong parameter type. You can use Equals as an instance level method or a type level (static) method:

string.Equals(str1, str2, StringComparison comp);

str1.Equals(str2, StringComparison comp);

So, in both, you need StringComparison, not StringComparer. And your one:

totalValue += Session["IsChauffeurUsed"].ToString().Equals("Yes", StringComparison.CurrentCultureIgnoreCase) ? 80 : 0;
like image 193
amiry jd Avatar answered Sep 24 '22 16:09

amiry jd