Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# .equals vs ==

string s1 = "test";
string s2 = "test";
string s3 = "test1".Substring(0, 4);
object s4 = s3;

Console.WriteLine($"{object.ReferenceEquals(s1, s2)} {s1 == s2} {s1.Equals(s2)}");
Console.WriteLine($"{object.ReferenceEquals(s1, s3)} {s1 == s3} {s1.Equals(s3)}");
Console.WriteLine($"{object.ReferenceEquals(s1, s4)} {s1 == s4} {s1.Equals(s4)}");

/*
True True True
False True True
False False True
*/
Comment

== vs equals c#

string s1 = "test";
string s2 = "test";
string s3 = "test1".Substring(0, 4);
object s4 = s3;

Console.WriteLine($"{object.ReferenceEquals(s1, s2)} {s1 == s2} {s1.Equals(s2)}");
Console.WriteLine($"{object.ReferenceEquals(s1, s3)} {s1 == s3} {s1.Equals(s3)}");
Console.WriteLine($"{object.ReferenceEquals(s1, s4)} {s1 == s4} {s1.Equals(s4)}");
//Output for these 6 comparisons:  
True True True
False True True
False False True
Comment

PREVIOUS NEXT
Code Example
Csharp :: Call Thread in C# 
Csharp :: unity get audio clip length 
Csharp :: How to make a simple console select screen using C# ReadKey 
Csharp :: Remove access to admin from deleting the file in C# 
Csharp :: c# read excel file using epplus save to datatable 
Csharp :: unity auto scroll 
Csharp :: c# sharepoint get users from column 
Csharp :: ArgumentException: Input Key named: Fire1 is unknown 
Csharp :: how to write text in specific position in c# 
Csharp :: c# list keyvaluepair update value 
Csharp :: c sharp convert string time into 24 hours time 
Csharp :: xamarin set environment variables 
Csharp :: conncet oracle database in c# visual studio 
Csharp :: unity reload active scene 
Csharp :: interop C# save as and replace 
Csharp :: asp net c# browser cursor wait 
Csharp :: v-slot 
Csharp :: ado net execute sql query 
Csharp :: unity stop velocity movement 
Csharp :: c# multiplicate char 
Csharp :: c# recorrer una lista 
Csharp :: how to set the current user httpcontext.current.user asp.net -mvc 
Csharp :: what is failure 
Csharp :: display none asp.net 
Csharp :: unity GUI TextField enter 
Csharp :: c sharp async 
Csharp :: unity screen size fix 
Csharp :: change physics material unity 
Csharp :: c# how to initialize an array 
Csharp :: how to remove from list from index c# 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =