PC Review


Reply
Thread Tools Rate Thread

C# Convertee - Help with IF statement syntax

 
 
TisMe
Guest
Posts: n/a
 
      13th Nov 2007
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.

 
Reply With Quote
 
 
 
 
Peter Duniho
Guest
Posts: n/a
 
      13th Nov 2007
On 2007-11-13 14:42:38 -0800, TisMe <(E-Mail Removed)> said:

> 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

 
Reply With Quote
 
Chris Shepherd
Guest
Posts: n/a
 
      13th Nov 2007
TisMe wrote:
> (e.Row.Cells[1].Text.ToLower() = "jake"))


You need another = here, it thinks you're trying to assign.

> (e.Row.Cells[1].Text.ToLower() == "jake"))


Chris.
 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      13th Nov 2007

You have "=" in your if statements, should be "==".

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.



On Tue, 13 Nov 2007 14:42:38 -0800, TisMe
<(E-Mail Removed)> wrote:

>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.


 
Reply With Quote
 
TisMe
Guest
Posts: n/a
 
      14th Nov 2007
Yup - I am coming from VB!

Thanks for your replies!

 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      15th Nov 2007

"TisMe" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Yup - I am coming from VB!
>
> Thanks for your replies!
>


you might find this useful:

http://labs.developerfusion.co.uk/co...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!!!";
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Word Perfect 8 be convertee to Quattro format? =?Utf-8?B?Q29sdHQ=?= Microsoft Excel Misc 1 17th Jan 2005 12:47 PM
Can Word Perfect 8 be convertee to Quattro format? =?Utf-8?B?Y29sdHRAY294Lm5ldA==?= Microsoft Excel Misc 0 17th Jan 2005 08:33 AM
select statement into if statement in an event code (syntax error =?Utf-8?B?dG90YQ==?= Microsoft Access VBA Modules 1 12th Dec 2004 11:13 AM
Statement syntax =?Utf-8?B?SmVhbm5pZQ==?= Microsoft Access Reports 9 11th Nov 2004 03:06 PM
IIF Statement Syntax ? Dave Elliott Microsoft Access Forms 4 15th Apr 2004 08:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 AM.