if(operatorStack.Peek() = '*')
	{
		//lowerPrecedence = true;
		strPostfix += operatorStack.Pop();
	}

OK I could really use some help here, I've tried this and other forums, and with all the superprogrammers we have out there no one will help me out on this.....

Why am I getting a ": The left-hand side of an assignment must be a variable, property or indexer" error? I understand that its probably trying to assign the character to a peek operation, rather than testing the condition. Ive tried using "==" but that doesn't help either. Can ANYONE give me some insight???????????????

Well I don't know the whole program, but for sure it's certain that '=' is an assignment operator. you need to use a comparison operator with if statement. If you are using = then you assigning the character '*' to the function operatorStack.Peek(). Try declaring a variable and assign the value to it, and then try to go to the condition. Also I'm not sure what exactly you want to do, but maybe there could be a problem with the statement inside if.

Firstly, to whoever asked.....

I am using VS .NET 2003 on XP.

Secondly, whats funny is that I put that I have Already tried using a double equal sign. Still doesn't work. I get an error stating that '==' cannot be applied to operands 'char' and 'object'.

As to my intent, it is for a infix/prefix/postfix conversion program. That statement is part of a switch statement to determine whether a number popped off the top of my stack is either a operand, operator, opening/closing parenthesis etc....


simon

Simon,

See if this helps:

object nextItem = operatorStack.Peek();
if( nextItem != null && nextItem.ToString() == "*" )
	{
		//lowerPrecedence = true;
		strPostfix += operatorStack.Pop();
	}if(operatorStack.Peek() = '*')
	{
		//lowerPrecedence = true;
		strPostfix += operatorStack.Pop();
	}

Sorry, The funny part was in using an assignment operator instead of an evaluator operator.
Peek returns the first index from the internal array. The array holds objects. You have to cast objects to the correct type for an evaluation statement.

Ya I actually had to cast the variable I was using for my switch statement. I also tried the object nextItem = stack.Pop()....

However, what immediately stood out to me was ToString() . I dont know why I missed that, but thank you. I haven't tried it yet, but Im almost positive that will fix my problem.

This article has been dead for over six months. Start a new discussion instead.