Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I m new to c#. i need to know purpose of === operation in c#. can anyone explain me simple. Thanks n Advance.
Posted

It looks like you're mistaking JavaScript for C#. I suspect that you have seen C# code injecting JavaScript into a web client page - hence where you would have seen ===. In JavaScript, the === operator tests for identity equality. No type conversion is done with this operator.
 
Share this answer
 
There is no such operator in C#. Refer - C# Operators[^], which list all the available operators.

But this operator is available in JavaScript.
Refer - JavaScript Comparison and Logical Operators[^]
Quote:

=== exactly equal to (equal value and equal type)

x==="5" false
x===5 true
So, it checks the DataType as well as value.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Apr-15 12:26pm    
Sure, a 5.
—SA
Thanks man. :)
There is no === operator in c#.

Here is a list of all C# operators: http://msdn.microsoft.com/en-us/library/6a71f45d.aspx[^]
 
Share this answer
 
There is no === operator in C#.

There is an = operator (= Operator (C# Reference)[^]) which is an assignment operator

There is an == operator (== Operator (C# Reference)[^]) which is an equality operator

But there is definitely no === operator. Where did you get it from?
 
Share this answer
 
=== Operator is not used in C#,
it is used in Javascript as === Operator [^]
 
Share this answer
 
Yes, there are no === in C#, but I just to elaborate more for sharing and learning purpose:
"===" exists In PHP and JavaScript, the former is called "Identical" while the later "Strict Equal"
In PHP and JavaScript, "===" returns true if the left side is equal to the right side and they are of the same type, e.g. 2 === "2" returns false;
In PHP and JavaScript, "==" returns true as long as they are equal even they are of different type e.g. 2 == "2" return true
 
Share this answer
 
v2
Comments
Ron Beyer 27-Jan-14 9:45am    
"In contrast, "==" returns true as long as they are equal even they are of different type e.g. 2 == "2" return true"

Maybe in Java or PHP, but not in C#, you may want to clarify that.
Peter Leow 27-Jan-14 9:54am    
I was referring to PHP and JavaScript. I have amended it to make it clearer. Thanks for pointing out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900