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 :: How to fill text with 2 different color/texture 
Csharp :: entity framework get all 
Csharp :: f sharp make parameter mutable 
Csharp :: blazor data annotation diaply name 
Csharp :: c# get the return value of a func 
Csharp :: copy array to array in c# 
Csharp :: mydata api .net 
Csharp :: select startup item visual studio 2019 
Csharp :: c# if loop 
Csharp :: vb.net check operating system 
Csharp :: int to binary string with 4 characters 
Csharp :: C++ program obtein volume in windows 
Csharp :: how to add an embedded resource in visual studio code 
Csharp :: same click method lots of buttons c# 
Csharp :: telerik mvc grid scroll 
Csharp :: check which activity in focus in android 
Csharp :: The anti-forgery cookie token and form field token do not match. 
Csharp :: unity dictionary foreach remove 
Csharp :: insert keys automatically dictionary in c# 
Csharp :: ########## 
Csharp :: C# Fibonacci list 
Csharp :: how to make a 2d character move in unity 2020 
Csharp :: c# 2 timespan return yesterday 
Csharp :: c# unzip all archive files inside directory 
Csharp :: how to split string into a list ignoring number of spaces c# 
Csharp :: firepower 4125 License update 
Csharp :: read dxf file c# 
Csharp :: how to make your player movr the way you are rotated in unity 
Csharp :: itext7 c# memorystream 
Csharp :: c# linq aggregate string builder 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =