> works but = doesn't

  • Thread starter Thread starter Laurel
  • Start date Start date
L

Laurel

If I use the following clause in my code I get two errors on this line.

if (dsFacultyBio.Tables[strTable].Rows.Count = 0)

The errors are

C:\DEV QX C#\6.4.1\QX.Data\QXFaculty.cs(318): Cannot implicitly convert type
'int' to 'bool'
and

C:\DEV QX C#\6.4.1\QX.Data\QXFaculty.cs(318): Property or indexer
'System.Data.InternalDataCollectionBase.Count' cannot be assigned to -- it
is read only


BUT!!!! If I change the = sign to a > sign, it works fine. This works
fine.

if (dsFacultyBio.Tables[strTable].Rows.Count > 0)

What should I be doing to make this work with the equality?

tia

las
 
Laurel said:
If I use the following clause in my code I get two errors on this line.

if (dsFacultyBio.Tables[strTable].Rows.Count = 0)

Should be:

if (dsFacultyBio.Tables[strTable].Rows.Count == 0)

Note the double equals.

HTH
 
Laurel said:
If I use the following clause in my code I get two errors on this line.

if (dsFacultyBio.Tables[strTable].Rows.Count = 0)

The errors are

C:\DEV QX C#\6.4.1\QX.Data\QXFaculty.cs(318): Cannot implicitly convert type
'int' to 'bool'
and

C:\DEV QX C#\6.4.1\QX.Data\QXFaculty.cs(318): Property or indexer
'System.Data.InternalDataCollectionBase.Count' cannot be assigned to -- it
is read only


BUT!!!! If I change the = sign to a > sign, it works fine. This works
fine.

if (dsFacultyBio.Tables[strTable].Rows.Count > 0)

What should I be doing to make this work with the equality?

In all of the C-like languages (C, C++, Java, C#), a single = indicates
assignment. An equality comparison is ==.

That means that the compiler read what you wrote as: "Assign 0 to
dsFacultyBio.Tables[strTable].Rows.Count, then use the assignment
result (0) as a boolean condition in the "if" statement." Thus the two
messages.
 
Thanks for the explanation. Somewhere along the line I thought == applied
to strings.

Bruce Wood said:
If I use the following clause in my code I get two errors on this line.

if (dsFacultyBio.Tables[strTable].Rows.Count = 0)

The errors are

C:\DEV QX C#\6.4.1\QX.Data\QXFaculty.cs(318): Cannot implicitly convert
type
'int' to 'bool'
and

C:\DEV QX C#\6.4.1\QX.Data\QXFaculty.cs(318): Property or indexer
'System.Data.InternalDataCollectionBase.Count' cannot be assigned to --
it
is read only


BUT!!!! If I change the = sign to a > sign, it works fine. This works
fine.

if (dsFacultyBio.Tables[strTable].Rows.Count > 0)

What should I be doing to make this work with the equality?

In all of the C-like languages (C, C++, Java, C#), a single = indicates
assignment. An equality comparison is ==.

That means that the compiler read what you wrote as: "Assign 0 to
dsFacultyBio.Tables[strTable].Rows.Count, then use the assignment
result (0) as a boolean condition in the "if" statement." Thus the two
messages.
 
Back
Top