// use System
using System;
// create class
class EqualityChecker
{
// main method
static void Main()
{
See AlsoHow to compare Objects in TypeScript | bobbyhadz.NET == and .Equals() – Passion for CodingDifference between == and .Equals method in c#Equality operators - test if two objects are equal or not equal - C#// create some values
string name = "Johnny";
string platform = "Edpresso";
bool isGreat = true;
bool isHard = false;
bool isCSharp = true;
int num1 = 3 + 4; // = 7
int num2 = 5 + 6; // = 13
See AlsoCompare strings in C#// compare them using
// the `Equals()` method
PrintEquals((string)name, (string)platform);
PrintEquals(name, name);
PrintEquals(isGreat, isHard);
PrintEquals(isGreat, isCSharp);
PrintEquals(num1, num2);
PrintEquals(num1, num1);
}
// check string objects method
static void PrintEquals(object obj1, object obj2){
if(obj1.Equals(obj2)){
Console.WriteLine("Both of the values are equal");
}else{
Console.WriteLine("Both of the values are not equal");
}
}
}
Educative Answers - Trusted Answers to Developer Questions (2024)
Top Articles
5 tipos de maletas de viaje y consejos para elegir
Se agotó nueva moneda coleccionable de ¢500 calidad Flor de Cuño, solo queda la que cuesta ¢25.000
The Influence and Longevity of Charles Laughton’s The Night of the Hunter – Establishing Shot
Apple’s 2024 Pride Collection shines light on LGBTQ+ communities
Latest Posts
15 Características de la Losa Maciza como Parte de los Sistemas Estructurales | homify
¿Qué es más saludable, las carnitas o la barbacoa?
Article information
Author: Dong Thiel
Last Updated:
Views: 6377
Rating: 4.9 / 5 (79 voted)
Reviews: 94% of readers found this page helpful
Author information
Name: Dong Thiel
Birthday: 2001-07-14
Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071
Phone: +3512198379449
Job: Design Planner
Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing
Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.