Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
In C#, a comparison operator is a binary operator that takes two operands whose values are being compared. Comparison operators are used in conditional statements, especially in loops, where the result of the comparison decides whether execution should proceed. They form the key to program flow control, known as conditional processing.
Comparison operators include:
Comparison operators are also known as relational operators.
Comparison operators have the following features:
In the .NET Framework, the System.String class is used for actions related to strings, such as manipulation, comparison and concatenation. It overloads the == operator to check for equality of contents of string type operands and compares the reference of the operand(s), if they are not of string type. Version 4.0 of the .NET Framework provides the facility for dynamic typing, by which the compiler can perform all the appropriate conversion necessary for comparison purposes.
When comparing objects having nested classes, comparison can be based on a reference pointing to a nested object that has to be compared (deep comparison) or on the values of the objects. This decision should be fixed in the design stage of an application. For comparison between floating point numbers, values should be rounded to an acceptable level for the application.