C# Convertee - Help with IF statement syntax

T

TisMe

Hi All,

I have the following if statement:

if ((e.Row.RowType = DataControlRowType.DataRow) &&
(e.Row.Cells[1].Text.ToLower() = "jake"))
{
e.Row.Cells[1].Text += "ALERT!!!";
}

I am getting the following compilation error on the first line shown
above:
CS0131: The left-hand side of an assignment must be a variable,
property or indexer

Can anyone help? I've tried a single ampersand, which gives me the
same error.

Basically, I am trying to say:

if ((this evaluates to true) AND (this evaluates to true)) Then
DO THIS
end if

Any help/advice will be much appreciated.

Thank you.
 
P

Peter Duniho

I have the following if statement:

if ((e.Row.RowType = DataControlRowType.DataRow) &&
(e.Row.Cells[1].Text.ToLower() = "jake"))
{
e.Row.Cells[1].Text += "ALERT!!!";
}

I am getting the following compilation error on the first line shown
above:
CS0131: The left-hand side of an assignment must be a variable,
property or indexer

You must be coming from VB.

You need "==" instead of "=" in your comparisons. A single equals is
strictly an assignment in C# (and other languages). Unlike VB,
assignments are evaluated expressions as well and so are legal anywhere
any expression is, including inside an if() statement, so the language
needs some other way to tell the difference than just context. It does
this by not overloading the "=" in the way that VB does.

Pete
 
L

Liz

TisMe said:
Yup - I am coming from VB!

Thanks for your replies!

you might find this useful:

http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx


it will take this:

If (e.Row.RowType = DataControlRowType.DataRow) AndAlso
(e.Row.Cells(1).Text.ToLower() = "jake") Then
e.Row.Cells(1).Text += "ALERT!!!"
End If

and convert it to this:


{
if ((e.Row.RowType == DataControlRowType.DataRow) &&
(e.Row.Cells(1).Text.ToLower() == "jake")) {
e.Row.Cells(1).Text += "ALERT!!!";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top