Stuck Stuck - 15 days ago 5
C# Question

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

When I am applying this line of code in my .cs file,

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

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


and I got this error : . Member 'object.Equals(object, object)' cannot be accessed with an instance reference; qualify it with a type name instead.

I am unsure about the issue and I hope you guys can help me out. Many thanks.

Answer
int totalValue = 0;
int total = 0;
totalValue = int.Parse("2".ToString()) * int.Parse("2".ToString());
string s = "Yes";
totalValue += s.Equals("Yes",StringComparison.CurrentCultureIgnoreCase) ? 80 : 0;
Comments