- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Double.Equals() Method in C# with Examples
The Double.Equals() method in C# is used to return a value indicating whether two instances of Double represent the same value.
Syntax
The syntax is as follows −
public bool Equals (double obj); public override bool Equals (object ob);
The obj parameter of the first syntax is a Double object to compare to this instance, whereas the obj of the second parameter is an object to compare with this instance.
Example
Let us now see an example −
using System; public class Demo { public static void Main() { double d1 = 150d; double d2 = 150d; Console.WriteLine("Double1 Value = "+d1); Console.WriteLine("Double2 Value = "+d2); Console.WriteLine("Are both the double values equal? = "+d1.Equals(d2)); } }
Output
This will produce the following output −
Double1 Value = 150 Double2 Value = 150 Are both the double values equal? = True
Example
Let us now see another example −
using System; public class Demo { public static void Main() { double d1 = 150d; object ob1 = 1/2; Console.WriteLine("Double1 Value = "+d1); Console.WriteLine("Object Value = "+ob1); Console.WriteLine("Are both the values equal? = "+d1.Equals(ob1)); } }
Output
This will produce the following output −
Double1 Value = 150 Object Value = 0 Are both the values equal? = False
Advertisements