#### Archived

This topic is now archived and is closed to further replies.

# question on ==

This topic is 6479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok i want to know exactly what this is....yes im a newbie as its easy to tell heres an example else if(age==100) whats the "==" in the above thing for is there a particluar reason why there is two equal signs to say that its equal? - Grimey

##### Share on other sites
It tests for equality.
When you use one = sign, it is an assignment statement.
val = 5; // the number 5 is put in val
(val == 10); // see if val contains the value 10

Martee
Magnum Games.NET
All your code are belong to us.

##### Share on other sites
okay look at the following code:

---
int age = 0;
if (age == 0)
do something here

if (age = 10)
do something else
---

the difference is that the "==" is a test for equality, whilst the "=" is a assign operator. So age == 0 returns true or false. Whilst age = 0 says let age be 0.

##### Share on other sites
The "==" operator is an equality operator. This is NOT the same as the "=" operator which is the assignment operator.

As an example:

age = 100;
This assigns the value of 100 to the variable age.

(age == 100)
This compares the value that is in age to 100. If it is the same then the expression is evaluated to true.

So you could say:
bool isEquals = ( age == 100 )

This assigns isEquals to either true if age is equal to 100 or false if not.

-------
Andrew

##### Share on other sites
damn, you beat me by 2 seconds

##### Share on other sites
Haha

Martee
Magnum Games.NET
All your code are belong to us.

##### Share on other sites
thanks for the help

1. 1
2. 2
3. 3
Rutin
18
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633659
• Total Posts
3013216
×